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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -