delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/25/01:23:54

Message-ID: <392CB951.34B432E6@chemistry.uq.edu.au>
Date: Thu, 25 May 2000 15:25:37 +1000
From: Chris Miller <c DOT miller AT chemistry DOT uq DOT edu DOT au>
X-Mailer: Mozilla 4.72 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Random numbers
Reply-To: djgpp AT delorie DOT com

Hello,
I have read what the function rand() is supposed to do, however it seems
to produce a very different response on my computer from what I would
expect.

If RAND_MAX is set to 100, then a call to rand() should return an
integer between 0 and 100.  However, on my computer, a call to rand()
generates a number between what appears to be hundreds of millions and
0, even with RAND_MAX set to 100.

The computer I am using uses 4-byte integers (32-bit).   Should I use
short integers instead?  Alternatively, do I need to separately
recompile the library to include the changed RAND_MAX value rather than
just place it at the top of my *.h file?  Or is there another function
that would be better to use, eg rand48?

Ideally, I am attempting to generate a random integer between 0 and
1,000,000.

Thank you in advance,
Chris Miller



- Raw text -


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