It may depend on how you are getting the random number. For example, <i>rand</i> can be found in <i>stdlib.h</i>. To use it, you would do something like:<br><br>int x;<br>x = rand(); // a random number<br>x = rand(); // another random number<br>x = rand(); // another random number<br><br> To use <i>random</i>, you will need to include <i>stdlib.h</i> and <i>time.h</i> for <i>randomize</i>. You could then use it like:<br><br>randomize();<br>int x;<br>x = random(100); // returns random integer between 0 and 99<br>x = random(100); // returns another random integer between 0 and 99<br>x = random(100); // returns another random integer between 0 and 99<br><br> Another common random number generator is <i>srand</i> (also in <i>stdlib.h</i>) which uses a "seed."<br><br>int x;<br>srand(12348);<br>x = rand(); // a random number<br>x = rand(); // another random number<br>x = rand(); // another random number<br><br> In reality, all of these are pseudo-random generators. <i>srand</i> is very popular since you can give it the current time as a seed to make it appear more random.<br><br>#include <time.h><br>.<br>.<br>.<br>time_t t;<br>srand((unsigned) time(&t));<br>x = rand(); // a random number<br>x = rand(); // another random number<br>x = rand(); // another random number<br><br> Hope this helps.<br> <p>James P. Cottingham<br><a href=mailto: > </a><br><a href=
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.