generating random numbers?

Started by
3 comments, last by jimiwa 19 years, 10 months ago
What function should I use to generate random numbers and how do I set the random number seed to the timer? I''m using Visual C++ .net, just in case that makes any difference (I don''t know if it does or not)
Advertisement
STFW.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
you use .NET, so just use the Random class, like this
Random rnd = new Random();int i = rnd.Next(0, 9); 

this will generate an integer between 0 and 9

[edited by - dave768k on June 4, 2004 2:20:18 PM]
rand() for the random number and srand(timeGetTime()) to seed it
or srandomdev() to seed it

--------------------------------------------------------
Life would be so much easier if we could just get the source code.
--------------------------------------------------------Life would be so much easier if we could just get the source code.

This topic is closed to new replies.

Advertisement