delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/04/30/15:15:20

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Date: Mon, 30 Apr 2001 21:58:18 +0400
From: egor duda <deo AT logos-m DOT ru>
X-Mailer: The Bat! (v1.45) Personal
Reply-To: egor duda <cygwin AT cygwin DOT com>
Organization: deo
X-Priority: 3 (Normal)
Message-ID: <10516333816.20010430215818@logos-m.ru>
To: HRahman10 AT aol DOT com
CC: cygwin AT cygwin DOT com
Subject: Re: Random Number Generator
In-reply-To: <32.143dcec3.281efce6@aol.com>
References: <32 DOT 143dcec3 DOT 281efce6 AT aol DOT com>
Mime-Version: 1.0

Hi!

Monday, 30 April, 2001 HRahman10 AT aol DOT com HRahman10 AT aol DOT 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 AT logos-m DOT ru ICQ 5165414 FidoNet 2:5020/496.19



--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019