function - Lua 5.1.4 math.random not actually random -
my problem when write math.random(10)
not random give me output:
1 6 2 9
and if have used example:
local colors = {"orang","blue","red","yellow","black"} print(colors[math.random(#colors)]) print(colors[math.random(#colors)]) print(colors[math.random(#colors)]) print(colors[math.random(#colors)]) print(colors[math.random(#colors)]) print(colors[math.random(#colors)]) print(colors[math.random(#colors)]) print(colors[math.random(#colors)]) os.execute 'pause'
the output always:
orange red orange black red red blue black
this output, how random????
you're misunderstanding random
does:
it's pseudorandom number generator. means that, given specific seed, give exact same sequence of numbers.
typically, use seed external source, e.g. use current time seed (warning: cryptologically dangerous!).
please read on pseudorandom , how use lua's random library.
Comments
Post a Comment