Re: Mersenne Twister

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

Thanks for that. I agree with your observations and have amended my code
accordingly.

I have been using another randomiser function that is a little more
unpredicatable. It works by using the normal Euphoria supplied rand()
function, except that at random times, it alters the seed value to a random
value. It is best used for programs that run for more than a few seconds.

-------------------
atom rtime
rtime = time()
global function rand_dp(integer i)
    if time() > rtime + rand(3) then
       set_rand( floor(rtime * time() * (rand(i)) / (rand(i))))
       rtime = time()
    end if
   return rand(i)
end function
----------------------


----- Original Message -----
From: <rforno at tutopia.com>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, September 22, 2001 6:02 AM
Subject: Mersenne Twister


>
> Derek:
> As per your request, I revised your implementation of the Mersenne
Twister.
> I found a slight disagreement with the original. The original poses:
> seed & 0xffffffff
> You instead code:
> remainder(seed, #FFFFFFFF)
> This does not give the same result for numbers >= 2^32 - 1, as should be
> most of the numbers generated by multiplying the previous one by 69069.
> Of course Euphoria does not accept:
> and_bits(seed, #100000000),
> but:
> remainder(seed, #100000000) is Ok and gives the same result.
> Maybe the initial matrix is not so important, as stated elsewhere, and
your
> variant is perhaps better, since the original generates only odd numbers,
> and yours generates odd and even numbers nearly at random, but only to
stick
> to the original...:)
> A similar problem occurs with the final result. The maximum value that y +
> #80000000 can attain is #FFFFFFFFF, and in this case the result is 1
higher
> than "range". This is equally solved by substituting range / #10000000
> instead of range / #FFFFFFFF.
> Even it may be preferable to write (y + #80000000) / #100000000 * range,
to
> protect against inaccuracies of the division of range by 2^32. Maybe Rob
has
> something to say
> about it.
> Best regards.
>
>
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu