Posted by Hal Bonnin on 1999-09-20
note. do not use that inside a loop. you will not get random numbers. top of source code have these lines #include <stdlib.h> #include <time.h> somewhere have this BEFORE you use rand() for the first time. dont do this too often or you will not get random numbers. srand((unsigned)time(null)); now every time you need a random number call rand() like this sprintf(Buffer,"Random number is %d",rand()); int DiceRoll=(int)(rand()/RAND_MAX)*5+1; six side dice i believe where RAND_MAX is the max possible number returned. RAND_MAX is not changable i believe. rand() will return 0 to RAND_MAX. use the integer example above to get a specific range of numbers the 5+1 is the max range, the 1 is minimum range
Previous post | Next post | Timeline | Home