[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: PRNG for Lua 4.0?
- From: Michael Horvath <mikh2161@...>
- Date: Tue, 10 Sep 2013 11:52:59 -0400
Yeah I tried local B = 2^23 and local B = 2^15, but it just made
matters worse.
Mike
On Tue, Sep 10, 2013 at 11:45 AM, Thijs Schreijer
<thijs@thijsschreijer.nl> wrote:
> See my previous message on truncation and Dirks reply regaring size.
>
> Looks to me
>> local B = 2^31
> Gets to big. Maybe experiment by reducing that value.
>
> Thijs
>
>
>
> -------- Oorspronkelijk bericht --------
> Van: Michael Horvath <mikh2161@gmail.com>
> Datum:
> Aan: Lua mailing list <lua-l@lists.lua.org>
> Onderwerp: Re: PRNG for Lua 4.0?
>
>
> Here's a PRNG someone suggested to me on Stack Exchange:
>
> -- rough adaptation of Park-Miller generator
> function srandom(seedobj, fVal1, fVal2)
> local B = 2^31
> local seed = seedobj[1]
> local k = mod(floor(seed/127773), B)
> seed = mod(16807 * (seed - mod(k * 127773, B)), B)
> seed = seed - mod(2836 * k, B)
> if (seed < 0) then
> seed = mod( seed + B - 1, B )
> end
> seedobj[1] = seed
> local temp_rand = seed/(B - 1)
> if not fVal1 then
> return temp_rand
> elseif not fVal2 then
> return floor(temp_rand * fVal1) + 1
> else
> return floor(fVal1 + 0.5 + temp_rand * (fVal2 - fVal1))
> end
> end
>
> It suffers from the same problem. But maybe it's easier to modify?
>
>
> Mike
>