delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/08/18:08:02

Date: Mon, 09 Jun 1997 10:09:29 -0700
From: Bill Currie <billc AT blackmagic DOT tait DOT co DOT nz>
Subject: Re: One method for small random nuimbers
To: Francois Charton <deef AT pobox DOT oleane DOT com>
Cc: djgpp AT delorie DOT com
Reply-to: billc AT blackmagic DOT tait DOT co DOT nz
Message-id: <339C297F.23A4@blackmagic.tait.co.nz>
Organization: Tait Electronics NZ
MIME-version: 1.0
References: <2 DOT 2 DOT 32 DOT 19970604162434 DOT 0069d50c AT gate> <3395B097 DOT 5077 AT cornell DOT edu>
<339830A6 DOT 672 AT blackmagic DOT tait DOT co DOT nz> <3397CBCF DOT 6536 AT pobox DOT oleane DOT com>

Francois Charton wrote:
> 
> Bill Currie wrote:
> >
> > Basicaly, I treat the number received from the main RNG as a
> > bit stream and pull off the bits as needed.
> >
> 
> I read about such a method being a bad thing in several books (Numerical
> Recipes warns a lot against this, and I remember reading something about
> it in Knuth, I'll dig it out tonight).

If you can send me a quote, that would be apreciated.

> In general, for RNG, "handmade" methods are always dangerous, and by
> slightly tweaking any good RNG, you can make a bad one out of it. An
> example of this was DJGPP rand() from a previous version (v2.00 and
> before): it used the ANSI rand() function, not excellent, but not
> terrible either, but instead of returning the number, it did some bit
> exchanging and shifting on the result; this looked like a good idea, but
> actually the resulting generator was bad (it had a low period).

This could vary well be true.  My test for improvement was just looking
at the distribution of results (I was using the RNG to simulate N
dice).  My original code just took the modulo of the random number and
the results were horible (sure I got a bell type curve, but every second
slot was about half (or maybe even 0) of what it should be (and the
period was noticably short).  Using the code I posted, the curve I got
was much closer to what I calculated it should be and I didn't get a
glaringly obviously short period.  Sure the period may have been even
shorter, but atleast it was out of phase with what I was doing.

> I believe books warn against interpreting random numbers as random
> sequences of bits because the subject (independence of the bits inside a
> random number) has not been researched enough.

I can believe that (hehe, I'm listening to Icehouse's ``Don't beleive
Anymore'' right now :) as I have the impression RNG *in general* are
poorly understood with only a few having been poured over.

> If randomness of the numbers is very important to you, I would be careful
> with this method.

I agree with you totaly and thank you for your comments.  If you can
point me in the right direction for information on testing RNGs, that
would be very kind of you.

> Francois

Bill
-- 
Leave others their otherness.

- Raw text -


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