local digits = {'1', '2', '3', '4', '5', '6', '8', '9'}
math.randomseed(os.time())
local result = digits[math.random(8)]
for i = 2, 50 do
result = result..digits[math.random(8)]
end
print(result)
--> 88854243421464255299891111895292628431988589634664
This is a Lua script designed to spit out fifty random digits, excluding 0 and 7. I can't seem to find the Lua randomness algorithm. Is it possible to find the value returned by os.time()?
To put it in layman's terms, here's how the script works:
- Define a list of eight single-character strings.
- Seed the pseudo-random algorithm with the number of seconds since midnight on January 1, 1970.
- Select a number between one and eight using the pseudo-random algorithm, then use that to select an item from the list. E.g. the number selected is seven, the algorithm picks the seventh item in the list.
- Add that item onto the end of the result. Repeat until the result is fifty digits long.
So because seven is left out, the random algorithm really spit this out:
77754243421464255288781111785282627431877578634664
But because seven is missing, seven and eight became eight and nine, yielding this:
88854243421464255299891111895292628431988589634664
To clarify, I'm trying to figure out how the random algorithm works to find the key that was entered as a random seed.
Also asked here: http://ift.tt/2oUD5rj and here: http://ift.tt/2oHoqDu and here: http://ift.tt/2oUSmZ3
Aucun commentaire:
Enregistrer un commentaire