Newsgroups: comp.ai.games,rec.games.roguelike.angband
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!nntp.sei.cmu.edu!cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!cs.utexas.edu!news.sprintlink.net!dish.news.pipex.net!pipex!news.mathworks.com!zombie.ncsc.mil!news.duke.edu!godot.cc.duq.edu!newsfeed.pitt.edu!dbisna.com!psinntp!psinntp!psinntp!psinntp!ncrgw2.ncr.com!ncrhub6!daynews!falcon!news
From: Dick Menninger <Dick.Menninger@DaytonOH.ATTGIS.COM>
Subject: Re: Random # Gen & "Fairness" (Was: What does '%' mean?)
X-Nntp-Posting-Host: 149.25.99.44
Message-ID: <DBDAEo.B79@falcon.daytonoh.attgis.com>
Sender: news@falcon.daytonoh.attgis.com (News administrative Login)
Reply-To: Dick.Menninger@DaytonOH.ATTGIS.COM (MENNID)
Organization: AT&T Global Information Solutions
X-Newsreader: DiscussIT 2.5.0.10 for MS Windows [AT&T Software Products Division]
References: <3tip8g$jt1@newsbf02.news.aol.com>
Date: Fri, 7 Jul 1995 22:28:00 GMT
Lines: 79


> ==========Bzenis, 7/6/95==========
> 
> It seems my original post has spawned some discussion on
> random number generation in Angband.  I'm the kind of player
> that will quit (w/o saving) and try again; BUT, there are a
> lot of players that take what they get (I might try it that way
> sometime) and it is nice that you can play either way.
>    However, is it really "fair" to the players that take what they
> get to have a cluster of low probability things happen to them?
> For example, how would you feel if you had a HIGH level character,
> that you've been working on for weeks (or months), DIE because
> you tried to Teleport (or even Phase Door) out of a situation, when
> you still had "enough" HP left, and it failed a BUNCH of times in a
> row because of the RNG?
> 
> Bernie

I have not seen much discussion of this, but most of the
random number generation in computer games (and most other
simulations) is badly done.  Some people thought that because
Knuth published some theory on part of the problem that it was
solved completely.  Well what Knuth published solves half of
the problem for a single random variable.  People make two big
mistakes in their random number generation.  They mess up
the second half of the problem of a single random varible and
they have no concept of separate random variables, thereby
mushing them all together.  These are two very distinct errors.
I actually worked out the theory behind this 20 years ago
at Bell Labs but I was in a development shop that was VERY
uninterested in that. So it never got published (I involves
partition theory and such to do the proofs).

The part Knuth published was how to do a mill to get maximum cycles.
The mill is the first half of an independent random variable.
The second half is mapping the mill value into a small integer range.
(Note that some problems need a large range of values, but
they can be further decomposed into several small range numbers,
that are separate random variables, which get combined carefully
to preserve the desired properties.  Floating point numbers with
a large number of digits in the mantissa is an example.  I will
ignore composition for now.)  The intuition behind licking this
came from looking at algebraic structures such as groups and
realizing that the composite size stuff generated substructure
that mirrored the bad properties of random number generators.
Whereas, prime sized stuff did complete cycles with any start.
So, create a 2**N mill (N == 32, 64, or what your machine does).
So, a given random variable has a fixed small range.  Pick a
prime that covers the range (if the range is prime, pick it, otherwise
pick the next bigger prime to be optimal).  Mod the mill value by
the prime and recrank if the result is out of range.  This gives
the best possible behavior in all cases.  Further, you can determine
the quality of your random variable to see if it meets your needs.
The measure of quality is how long a sequence of independent
values of the variable can be well represented.  If P is your prime,
and M = 2**N is the range of your mill then solve P**X = M for X
to get the sequence size.  For instance, if the range is 256, your
prime is 257, and X is slightly under 4.  This means a sequence
of 4 values is a little shakey, but not too bad.  Beyond that,
you have a problem.

Sharing a mill among several random variables is a bad idea
as far as sequences are concerned.  They are not independent
any longer.  Designing with great attention to random variables
also produces radically different behavior of games relative to
save/restore abuse.  Once you Establish the mill multiplier, addend,
and seed value for a random variable, it persists through saves,
thereby causing it to behave the same on restore in many cases
(you might be able to behave differently in some way before
the next sample is taken).

But remember, even with separate mill/prime-based random variables,
the sequences that are adequately generated are still surprisingly
small.  I cannot wait for 64-bit word machines.  They will double
the sequence length that can be easily generated.

Good Day
Dick

