Jump to content




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


  • You cannot reply to this topic
2 replies to this topic

#1 gknova61

  • Members
  • 74 posts

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

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 19 November 2012 - 04:59 PM

Try putting this at the top of your program:
math.randomseed( os.clock() )


#3 gknova61

  • Members
  • 74 posts

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() :(/>





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users