www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/25/13:55:57

Message-ID: <392D5391.E87DD3DE@earthlink.net>
From: Martin Ambuhl <mambuhl AT earthlink DOT net>
Organization: Nocturnal Aviation
X-Mailer: Mozilla 4.73 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Random numbers
References: <392CB951 DOT 34B432E6 AT chemistry DOT uq DOT edu DOT au>
Lines: 26
Date: Thu, 25 May 2000 16:22:32 GMT
NNTP-Posting-Host: 63.23.128.220
X-Complaints-To: abuse AT earthlink DOT net
X-Trace: newsread2.prod.itd.earthlink.net 959271752 63.23.128.220 (Thu, 25 May 2000 09:22:32 PDT)
NNTP-Posting-Date: Thu, 25 May 2000 09:22:32 PDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com


Chris Miller wrote:

> 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.

RAND_MAX is not for you to set.  It reports to you the limit of values
generated by rand() is.  One way to use it is:

#include <stdlib.h>

int foo(int limit)
{ return limit*(rand()/(1.+RAND_MAX)); }



-- 
Martin Ambuhl	mambuhl AT earthlink DOT net

What one knows is, in youth, of little moment; they know enough who
know how to learn. - Henry Adams

A thick skin is a gift from God. - Konrad Adenauer

- Raw text -


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