Jump to content
Powerhorst

Math:Random repeats results

Recommended Posts

Hey there!

 

Not entirely sure if this is just on my side, so feel free to delete this if I'm wrong.

 

I'm using Math:Random for my everyday needs in random numbers but it seems like I'm getting

the same numbers every time.

 

z = Math:Random(-10,10)

 

So even after restarting my project a few times, z always gets the same value.

The info-page states that LUA uses Math:Rnd instead but that just throws an error.

Sorry for the inconvenience if I'm just using it wrong but I can't find any other way so far.

 

 

Greets

Share this post


Link to post

I think I remember I had problems with Math:Random also. I ended up doing some thing like the below:

 

In App.lua:Start():

math.randomseed(Time:Millisecs())

 

Where ever you need a random number:

math.random(min,max)

Share this post


Link to post

in the lua math module, its lower case:

z = math.random(-10,10)

but this will have the same effect as you are getting now that it returns the same number. To vary the returned number, use the random seed:

math.randomseed(Time:Millisecs())
z = math.random(-10,10)

see here for more details: http://www.lua.org/manual/5.1/manual.html#5.6

 

Edit- hankinator beat me to it smile.png

Share this post


Link to post

EDIT:

 

Aaah.

 

Sorry for the trouble.

 

I just realised I was typing "math:random" instead of "math.random"

 

Really need to get me some Intellisense in the editor

 

Thanks a lot for the help smile.png

Share this post


Link to post

yep I had this problem till I looked it up on google and found out to use the random seed, and I also use math.random about 3-4 times to try and make it as random as possible.

Share this post


Link to post
Guest
This topic is now closed to further replies.
×
×
  • Create New...