What's the best seed for generating random numbers in the Random class?
I heard making it time-based ensures absolute randomness but should this be from the 'Now' function or is the system.environment.tickcount value good enough?
try it yourself...get a bunch of random numbers with the same seed twice and you'll find that you get random numbers but they are exactly the same random numbers that you got last time.
that's what the seed is for.
it's similar to having to declare Randomize in VB6 to prevent this from happening.
Either of the values you mentioned would be fine, because they change. Theoreticly I guess getting the now value would be better as it could be possible to hit the same tick on a susequent execution of the app, although the likely hood is pretty low.
According to .Net documentation, the default seed is from the system clock, so you don't need to seed it--it will do it by itself. But, if it runs to fast to get different values from the clock, there is a suggestion on MSDN to take care of that:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.