Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random number generation

Status
Not open for further replies.

sophtwarez

Programmer
Jan 8, 2002
8
0
0
US
Hello all - how can I generate a random number *at run time* in C++? I'm thinking of something like Visual Basic's Rnd or, in Java, Math.random().
I've used rand() and it always generates the same number after compilation.

Thanks much,

dav1d
 
Did you want something like this???

#include <stdlib.h>//you may need to include

srand((unsigned)time(NULL)); //Only needs to be used once
Variable = rand()%20;//'20' is the max number

Hope this help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top