Rick Posted October 2, 2015 Share Posted October 2, 2015 I don't see a seeding function in Math. How can I seed the random generator? Normally I would use: math.randomseed(os.time) but in sandbox mode you can't use 'os' object. Passing Time:GetCurrent() really doesn't help since it's the running time of the app. I'm stuck with the same numbers each run atm. Quote Link to comment Share on other sites More sharing options...
shadmar Posted October 2, 2015 Share Posted October 2, 2015 You can use this unless you're doing randoms before rendering starts. There will be tiny variations in rendering speed. first 5 will always be the same since GetSpeed is then 0 after first frame you will have randoms. function Script:UpdateWorld() math.randomseed(Time:GetSpeed()*43758.5453) for x=0,4,1 do System:Print(math.random()) end System:Print(" ---- ") end Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rick Posted October 2, 2015 Author Share Posted October 2, 2015 I was doing this in Script:Start(). I could use this and hack around it, but LE really needs to expose some way to do a real seeding of it's random numbers. Thanks for the idea shadmar. 1 Quote Link to comment Share on other sites More sharing options...
shadmar Posted October 2, 2015 Share Posted October 2, 2015 LE really needs to expose some way to do a real seeding of it's random numbers Aha.. math.randomseed(Time:Millisecs()) always gives you randoms even in Start(). Seems like Time:Millisecs() returns the system time in milliseconds, not apptime. http://www.leadwerks.com/werkspace/page/api-reference/_/time/timemillisecs-r496 So there you go.. proper way 1 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rick Posted October 2, 2015 Author Share Posted October 2, 2015 Interesting when I do it as the first line in Main.lua I don't get random numbers. Actually even in Start() I'm not getting random numbers. function Script:Start() math.randomseed(Time:Millisecs()) -- get random numbers and set the materials for our children self.combo = {} self.combo[1] = Math:Round(Math:Random(0, 9)) self.combo[2] = Math:Round(Math:Random(0, 9)) self.combo[3] = Math:Round(Math:Random(0, 9)) self.combo[4] = Math:Round(Math:Random(0, 9)) end Looks like I'll have to use Lua's math.random() with this as LE's must use something different where doing Lua's seeding doesn't work. I figured LE's Math:Random() was just using Lua's math.random() but I guess not Quote Link to comment Share on other sites More sharing options...
shadmar Posted October 2, 2015 Share Posted October 2, 2015 Yeah, I don't think you can seed LE's RNG using this. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.