Solarus-Games English Forum

Solarus => Development => Topic started by: Yosha on September 25, 2015, 08:56:23 AM

Title: Random...
Post by: Yosha on September 25, 2015, 08:56:23 AM
Hello, I don't know if anyone have already seen this, but I just saw yesterday that when I generate random numbers in a dialog, for each game I played, it was always the same numbers and in the same order...
Title: Re: Random...
Post by: Christopho on September 25, 2015, 09:06:45 AM
Like in most languages, you need to initialize a different random seed if you want different sequences of numbers.
See http://www.lua.org/manual/5.1/manual.html#pdf-math.randomseed
Title: Re: Random...
Post by: Yosha on September 25, 2015, 09:20:00 AM
Ok, thank you !
I use math.randomseed(os.time()) in map:on_started() and I have now a real random number !  :)
Title: Re: Random...
Post by: Christopho on September 25, 2015, 11:49:23 AM
You don't need to do it in map:on_started(), but only once when your quest starts. So, in sol.main:on_started().