www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/30/02:36:05

Date: Thu, 30 Jan 1997 09:28:51 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Pascal Massimino <massimin AT triere DOT ens DOT fr>
cc: djgpp AT delorie DOT com
Subject: Re: Random numbers
In-Reply-To: <5clv5m$n2m@nef.ens.fr>
Message-ID: <Pine.SUN.3.91.970130092652.17132G-100000@is>
MIME-Version: 1.0

On 28 Jan 1997, Pascal Massimino wrote:

>  * do not use the lowest bits of rand(). Too bad random properties.
>    Try printf'ing rand()&0x01 for instance, you'll be surprised.
>    So, better use   ( rand()>>4 ) or ( rand()>>7 ), for instance...

A much better way is to use `random' instead of `rand'.  It is a POSIX 
function (AFAIK) and is documented to generate numbers whose bits are 
*all* rundom; the docs even give you an example of using the lower 2 bits 
to get a random number between 0 and 3.

- Raw text -


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