Random Number Generator
Harold Hunt
huntharo@msu.edu
Mon Apr 30 12:16:00 GMT 2001
Beginning CS student? Thought so :)
Let me teach you how to debug your program:
1) Change your line that calls rand () to:
input1 = rand ();
2) Notice that random numbers are now generated.
3) Have your program print out the value of RAND_MAX:
printf ("RAND_MAX: %d\n", RAND_MAX);
4) Calculate the result, in integer math, when
dividing any integer smaller than RAND_MAX by
RAND_MAX. (Hint: the answer is zero)
5) Realize that what you really wanted was something like:
// Get random numbers from 0 and 9, inclusive
input1 = rand () % 10;
// Get random numbers from 1 and 10, inclusive
input1 = 1 + rand () % 10;
That was your freebie, from now on, ask general programming questions to a
list that is more suited to answering such questions; or, better yet, read
some programming books :)
Harold
--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple
More information about the Cygwin
mailing list