This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
gknova61's profile picture

Actual Random Number Generation? (math.random returning the same numbers)

Started by gknova61, 19 November 2012 - 03:16 PM
gknova61 #1
Posted 19 November 2012 - 04:16 PM
Here is the program code for those interested:
http://pastebin.com/MgPvdBpB

Basically, I'm trying to find a way to generate an 8-digit random number (program is currently generating 2, 4 digit numbers then merging them for more security :(/>/>), but the way i'm doing it is odd… it keeps returning the same numbers everytime i reboot the computer (this program is the startup program btw) and run the generator again. Take a look for yourself at around line 175

Try the program yourself, it'll generate a random number at first run but when you reboot it, and it generates a random number, that number is the same number as last time
Kingdaro #2
Posted 19 November 2012 - 04:59 PM
Try putting this at the top of your program:

math.randomseed( os.clock() )
gknova61 #3
Posted 19 November 2012 - 05:47 PM
Works perfect, thanks! I added in a slightly more complicated algorithim for getting the seed:
os.time()*os.clock()+os.computerID() :(/>/>