Reputation: 31
Can
System.Random(Int32).Next(minValue, maxValue) ;
be used as a sort of Linear Congruential Generator?
Upvotes: 1
Views: 146
Reputation: 31
So, the answer is NO. Because Random() changes from version to version in .NET. I cannot use Random(Int32).Next(minValue, maxValue) as a sort of Linear Congruential Generator. Ugh!
Upvotes: 1
Reputation: 11426
Yes, System.Random will always give the same next value given the same seed and boundaries, the constant is the seed which you can optionally supply. So you would NOT want to change the seed each time you call Next() as your line does, instead:
var myRandom = new Random(mySeed);
var value = myRandom.Next(minValue, maxValue);
var anotherValue = myRandom.Next(minValue, maxValue);
...
Upvotes: 0