saiz66 Posted June 8, 2004 Share Posted June 8, 2004 What is a good way to generate random numbers from 0 to 4 let's say? This is for visual c++. Thanks in advance! Link to comment Share on other sites More sharing options...
0 CdCViRus Posted June 8, 2004 Share Posted June 8, 2004 use can use rand() in stdlib.h or use can use clock_t t = time (NULL); int x = t & 0x1; return (x % 5); Link to comment Share on other sites More sharing options...
0 John Veteran Posted June 8, 2004 Veteran Share Posted June 8, 2004 Title edited for clarity Link to comment Share on other sites More sharing options...
0 random173 Posted June 8, 2004 Share Posted June 8, 2004 alternative way srand(time(NULL)); // seeds random number generator, so it generates it based on time, otherwise the random numbers are usually the same each time you run the program... so ... not really that random :) int rand_num = rand()%10+1; // random number between 1 - 10 (+1 because it starts at 0) for this way you need stdlib.h and time.h Link to comment Share on other sites More sharing options...
0 CdCViRus Posted June 9, 2004 Share Posted June 9, 2004 alternative way srand(time(NULL)); // seeds random number generator, so it generates it based on time, otherwise the random numbers are usually the same each time you run the program... so ... not really that random :) int rand_num = rand()%10+1; // random number between 1 - 10 ?(+1 because it starts at 0) for this way you need stdlib.h and time.h yeah, basically what I meant, but was too lazy to type :pp Link to comment Share on other sites More sharing options...
Question
saiz66
What is a good way to generate random numbers from 0 to 4 let's say? This is for visual c++. Thanks in advance!
Link to comment
Share on other sites
4 answers to this question
Recommended Posts