lua-users home
lua-l archive

Re: Lua 5.4 random number generator

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


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

AltStyle によって変換されたページ (->オリジナル) /