1. Random Number Generators in C
Hello,
I recently got in to Euphoria programming and have run in to a problem
or
two that maybe the List might have answers.
First, Not knowing what the Random Number Generator algorithm built into
Euphoria is and how random it is I went searching for a RNG I could port
into Euphoria. First I found Jeffrey Fielding had included in his Genlib.e
v1.0 a RNG but he did not document the source (or creator) of his RNG.
Which left me in the same boat.
So I tried to port the "Mersenne Twister" RNG which has a period of
(2^19937)-1. It requires a number of bitwise operations. I found Euphoria
does not have bitwise shift functions so I wrote code for that (shift_left
and shift_right --- I'll post these at the RDS site if anyone is
interested), but ran into a brickwall because bitwise operations in
Euphoria are limited to 32 bits. 64 bit XOR, AND, OR operators are required.
Ok. So I went looking for another code snippet that did not require so many
bitwise operations. I found a site that had posted a 17 line code snippet
in C by George Marsaglia (a guru of RNGs). The snippet has 8 different RNGs
but low and behold ran into the same problem the most of these require
64bit bitwise operators.
So what I am looking for is one of the following:
a) a documented RNG with a long period that passes at least in
part
Marsaglia's Diehard Tests
written in Euphoria.
b) a magic bullet that makes Euphoria do 64 bit logical
operations or an
include file that does so.
c) failing these, some help coding a dll in C that will contain
the 8
RNGs noted above.
I won't post the C code for the 8 RNGs unless the List thinks it's a good idea.
2. Re: Random Number Generators in C
Perhaps you can use two atom/sequence pairs to get the 64-bits you need. =
Have a high and low portion, and modify the shift functions to accommodate =
shifting over two sequences.
HTH,
Michael J. Sabal
>>> Joel Crook <joel at MAIL.K-A.COM> 02/10/00 02:06PM >>>
So what I am looking for is one of the following:
a) a documented RNG with a long period that passes at =
least in part
Marsaglia's Diehard Tests
written in Euphoria.
b) a magic bullet that makes Euphoria do 64 bit logical =
operations or an
include file that does so.
c) failing these, some help coding a dll in C that will =
contain the 8
RNGs noted above.
I won't post the C code for the 8 RNGs unless the List thinks it's a good =
idea.
3. Re: Random Number Generators in C
Joel Crook wrote:
> a magic bullet that makes Euphoria do
> 64 bit logical operations or an include
> file that does so.
If you stored the bits in a sequence:
{ 1, 0, 1, 0, 1, 1, 1 ... }
wouldn't the operations become trivial?
-- David Cuny
4. Re: Random Number Generators in C
----- Original Message -----
From: Cuny, David at DSS <David.Cuny at DSS.CA.GOV>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Thursday, February 10, 2000 1:43 PM
Subject: Re: Random Number Generators in C
> Joel Crook wrote:
>
> > a magic bullet that makes Euphoria do
> > 64 bit logical operations or an include
> > file that does so.
>
> If you stored the bits in a sequence:
>
> { 1, 0, 1, 0, 1, 1, 1 ... }
>
> wouldn't the operations become trivial?
Yes, otherwise this is known as string math, and you don't have the number
base conversion problems if you do all the math this way. String math is
terribly slow, since it cannot use any hardware, but there is no better
accuracy and no limits as to what can be done.
Kat
5. Re: Random Number Generators in C
- Posted by Everett Williams <rett at GVTC.COM>
Feb 10, 2000
-
Last edited Feb 11, 2000
Mike Sabal wrote:
>Perhaps you can use two atom/sequence pairs to get the 64-bits you need. Have
>a high and low portion, and modify the shift functions to accommodate shifting
>over two sequences.
>
>HTH,
>Michael J. Sabal
>
>>>> Joel Crook <joel at MAIL.K-A.COM> 02/10/00 02:06PM >>>
>
>So what I am looking for is one of the following:
> a) a documented RNG with a long period that passes at least in
> part
>Marsaglia's Diehard Tests
> written in Euphoria.
> b) a magic bullet that makes Euphoria do 64 bit logical
> operations or an
>include file that does so.
> c) failing these, some help coding a dll in C that will contain
> the 8
>RNGs noted above.
>
>I won't post the C code for the 8 RNGs unless the List thinks it's a good idea.
If you were able to get Mr. Masaglia's 8 RNGs, then you can download his
Diehard.zip that contains his RNG tester. It does run under windows in a
DOS window. Then, you can create a set of random numbers to from
Euphoria's RNG and feed them into it and we will all know whether RDS's
random function creates reasonably random sequences. If it does, you
won't need to convert any of that C code.
Everett L.(Rett) Williams
rett at gvtc.com