More on Random Number Generators in Euphoria

new topic     » topic index » view thread      » older message » newer message

>
>Hmm...  I don't know much about that.  I've written multiple-dice-rolling
>functions using rand(), and they give a proper-looking bell curve, so that's
>always seemed random enough for me.  How do you decide how random
>is random enough?  (on a philosophical sidenote, if you know how random
>something is, does that make it less random?)

The old test (mid '80s in Turbo Pascal of Turbo C) was to plot dots on an
NxN square. if a pattern showed up it was obvious that it was not really
random but predictable pattern. I wrote one similar to this in Euphoria for
a 400 x 400 square and got what I think may be some anomalous results.  I
have not had a chance to try coding another test I have seen which plots
the dots to the interior of a sphere and presents the results as in three
different windows (X,Y,Z Planes) which can be viewed to look for patterns.

How much randomness is good? In a board game if rolling a "die" is always
more likely to roll a 2 than a 6 you'd call the game unfair and the dice
loaded.

The tests for RNG (or more properly pseudo-random number generators) have
gotten more and more rigorous. Marsaglia issued a battery of tests (Called
the DieHard tests of course! smile) which the KISS code below passes (sorry
it's in C as Euphoria does not have completely equivalent code).

 The first three defines are RNGs. MWC has a period of 2^60. SHR3 has a
period of 2^32-1. and  the CONG a period of 2^32. The SWG has a period of
2^7578 but has some randomness shortcomings but by combining SWG with the
KISS generator which has a period of  2^123, you get a RNG that passes the
tests and has a period of  greater than 2^7700 or as my windows calculator
reports 8.53034532588326944571607353968e+2317.

In statistics and games that's a nice generator.


#define MWC    ((znew<<16)+wnew )
#define SHR3  (jsr^=(jsr<<17), jsr^=(jsr>>13), jsr^=(jsr<<5))
#define CONG  (jcong=69069*jcong+1234567)
#define KISS  ((MWC^CONG)+SHR3)

#define SWB   (c++,bro=(x<y),t[c]=(x=t[UC(c+34)])-(y=t[UC(c+19)]+bro))


>>      b) a magic bullet that makes Euphoria do 64 bit logical operations or
>an
>>include file that does so.
>
>Well, if you can assume that it'll be used on Pentium MMX-equipped PCs,
>maybe you could poke and call the machine code for PAND, POR, and
>PXOR...  (the MMX 64-bit bitwise instructions).  Don't know if that requires
>any special work, but I can try it.  If it works it'd be quicker than
>sequencizing them.

I also hear that the Pentium III has a hardware RNG but as I and most folks
don't currently have a PIII, it is a moot point.

I'd be interested in the code for the MMX 64bit operators...

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu