Powerhorst Posted February 22, 2015 Share Posted February 22, 2015 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 Link to comment Share on other sites More sharing options...
thehankinator Posted February 22, 2015 Share Posted February 22, 2015 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) 1 Link to comment Share on other sites More sharing options...
macklebee Posted February 22, 2015 Share Posted February 22, 2015 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 Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Powerhorst Posted February 22, 2015 Author Share Posted February 22, 2015 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 Link to comment Share on other sites More sharing options...
AnthonyPython Posted February 22, 2015 Share Posted February 22, 2015 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. OS: Windows 10 Pro CPU: i3-10100 CPU @ 3.60GHz GPU: NVIDIA 2060 Super - 8 GB RAM: 32 GB Link to comment Share on other sites More sharing options...
Recommended Posts