This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
RE: Random Number Generator
- To: <HRahman10 at aol dot com>, <cygwin at cygwin dot com>
- Subject: RE: Random Number Generator
- From: "Harold Hunt" <huntharo at msu dot edu>
- Date: Mon, 30 Apr 2001 15:14:02 -0400
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