pithhelmet Posted November 22, 2004 Posted November 22, 2004 Hi everyone - Is there a way to resead the timer to truly get a random number??? in my code block - i grab the random number hundreds of times a second, and it seems like the number isn't changing enough times.... is there a way to resead the timer?? thanks tony Quote
Wile Posted November 22, 2004 Posted November 22, 2004 If you reuse the same Random object for each subsequent call, this shouldnt be a problem as it would be a different number from the same first seed -> be a 'statistically random number' as they say in the help file ;). Only if you create a new Random object for every random value you need, you'll get into trouble with the seeding. There is an overload on the construction of the Random object for this. You can specify an integer as seed number. You could use an internal counter and increment it by one, starting with a base value that uses the Ticks property of the time, added with a incrementing counter you use for each subsequent call. Bit of copy and paste later we get ): myCounter++; Random rdm1 = new Random(myCounter + (int)DateTime.Now.Ticks); ps. havent tried running these two lines but it shouldnt be that hard to get working if I made a mistake ;). Quote Nothing is as illusive as 'the last bug'.
*Gurus* Derek Stone Posted November 22, 2004 *Gurus* Posted November 22, 2004 Don't use the [msdn]System.Random[/msdn] class. Use [msdn]System.Security.Cryptography.RNGCryptoServiceProvider[/msdn] instead. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.