www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/23/18:29:21

Date: Fri, 23 Sep 94 12:07:34 EDT
From: peprbv AT cfa0 DOT harvard DOT edu (Bob Babcock)
To: roalz AT varano DOT ing DOT unico DOT it
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: Problem with rand() (fwd)
Reply-To: babcock AT cfa DOT harvard DOT edu

> It seems that rand() returns alternately an even and an odd number
>    result += ((rand() % _sides) + 1);

It is not uncommon to find inadequate pseudorandom generators.  One thing
which may help when generating a small number from a random value is to make
the number depend on the high order bits returned by rand().  Right shifting
as many bits as possible before doing the modulo operation will probably work.

- Raw text -


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