rand() and examples
Michael Robertson
amigo at milton.u.washington.edu
Mon Oct 22 07:39:45 AEST 1990
I need some definite description how to use the rand() function in
C. Or, if someone can describe random() then that may help as well.
I'm creating a game that needs a random number between 1 and 13,
I want only 1 to 13, not 13.000001, etc. A "demo" I have locally
was:
include <time.h>
main()
{
unsigned seed=time(); /* grab seed from time() */
srand(seed); /* set seed */
int test_it;
test_it == rand()%14; /* rand() generates numbers,
% func. limits it..? */
printf("\nRand=%d", &test_it);
}
There's of course some stuff wrong with the above I believe.
If someone can e-mail me correct use of rand() and/or random(),
it'd be much appreciated..
thanks,
mike robertson
amigo at milton.u.washington.edu
More information about the Comp.lang.c
mailing list