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
- Subject: Re: Random Number Generator
- From: egor duda <deo at logos-m dot ru>
- Date: Mon, 30 Apr 2001 21:58:18 +0400
- CC: cygwin at cygwin dot com
- Organization: deo
- References: <32.143dcec3.281efce6@aol.com>
- Reply-To: egor duda <cygwin at cygwin dot com>
Hi!
Monday, 30 April, 2001 HRahman10@aol.com HRahman10@aol.com wrote:
Hac> Hi!, I'm writing a program using the random number genrator
Hac> rand() defined in <stdlib.h>. I've written the following program
Hac> to test it:
Hac> void main()
Hac> {
Hac> int input1, i;
Hac> srand(time(NULL));
Hac> for (i=0; i<20 ; i++)
Hac> {
Hac> input1 = rand() * 10 / (RAND_MAX + 1);
Hac> printf("random numbers %i\n",input1);
Hac> }
Hac> }
Hac> BUT, the results I get are all zeros. Is there something wrong
Hac> with the gcc compiler provided by cygwin, because I've tested
Hac> this program at university, and it outputs random numbers
Hac> correctly.
your program is wrong. RAND_MAX == INT_MAX == 0x7fffffff on cygwin.
so you've got integer overflow, RAND_MAX + 1 == -2147483648
Egor. mailto:deo@logos-m.ru ICQ 5165414 FidoNet 2:5020/496.19
--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple