lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Mar 26, 2018 9:38 AM, "albertmcchan" <albertmcchan@yahoo.com> wrote:
On Mar 23, 2018, at 6:31 PM, Coda Highland <chighland@gmail.com> wrote:

> On Fri, Mar 23, 2018 at 5:24 PM, Albert Chan <albertmcchan@yahoo.com> wrote:
>> You mean just two math.random(0) (128 bits) can predict the next one ?
>
> No, if you see the least significant bit of 128 consecutive calls to
> math.random, then you can predict the least significant bit of every
> call from there on out.
>

I tried print out 128 last bits (128 math.random calls), but I do not
see the pattern.  How does the prediction work ?

You can try it on lua 5.4.0-work1

function last128()
    for i=1,128 do io.write(math.random(0) & 1) end
end



It's not trivial. There's not a visible pattern but you can do math to reverse-engineer the internal state with that data. I don't know the technique myself.

/s/ Adam