c# - Fast random number generation - multiple times per ms -


this question has answer here:

i noticed, when using system.random, if next() called more 1 time in millisecond, returns same number (if has same parameters). assume random algorithm somehow concerns system's time, , dependent on that.

i'd call next() many times within single millsecond - there way this, same random class? if not, i'd appreciate resources/other methods of solving this.

this because when initialise new instance of random uses system clock seed. if twice, close enough together, you'll end using same seed , you'll same sequence of random numbers 2 instances.

the solution alluded in comments already, instantiate 1 random object , repeatedly call next() on it, you'll new random number every time.

var val1 = new random().next(); var val2 = new random().next(); // quite val1 , val2 same  var rnd = new random(); var val3 = rnd.next(); var val4 = rnd.next(); // unlikely val3 , val4 same 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -