Slastraf Posted August 3, 2016 Share Posted August 3, 2016 I want to know how to do that in lua. Quote Link to comment Share on other sites More sharing options...
Crazycarpet Posted August 3, 2016 Share Posted August 3, 2016 I'm confused as to what you're asking? By seed do you mean you have a given 'x' value already, and you want to generate a new one based on that? local x = 250.0 -- For example sake lets say this is our already known x value local offset = math.random(-25.0, 25.0) --Now we generate a random offset between -25.0 and 25.0 units. local x2 = x + offset --Add our offset to our x value to get our new x value (x2). Is that kind of what you're trying to do? or? Keep in mind if you're using this to generate positions to place physics objects you should be doing something to make sure this newly generated position is within the world boundaries and not under terrain like a hill or something... which is why you'd choose a suitable max and min offset for your math.random offset generation. You may be able to do some kind of AABB bounds checking to help ensure it's not going to intersect with other nearby entities. Just make sure you compare them as if they were both boxes to avoid situation where the position of the new entity isn't intersecting, but the max or the min boundary might be. 1 Quote Link to comment Share on other sites More sharing options...
Genebris Posted August 3, 2016 Share Posted August 3, 2016 I guess you are looking for default Lua math.randomseed() function. 1 Quote Link to comment Share on other sites More sharing options...
Slastraf Posted August 4, 2016 Author Share Posted August 4, 2016 function Script:Start() math.randomseed(tostring(self:MakeRndSeed())) for n = 0, 15 do num = math.random(9) System:Print(num) end end function Script:MakeRndSeed() local seed = 1 seed = Math:Random(1,9) seed = seed*10000000000 return Math:Round(seed) end I have this now. The MakeRndSeed just makes a random number , but its always the same at the start of the program. I need to find a way around it fast now. Maybe I will just let the player put a random number in a textfield, or let him press a button during runtime and from the runtime in millisecs make the seed actually random Quote Link to comment Share on other sites More sharing options...
Genebris Posted August 4, 2016 Share Posted August 4, 2016 math.randomseed(os.time()) 1 Quote Link to comment Share on other sites More sharing options...
shadmar Posted August 4, 2016 Share Posted August 4, 2016 If sandboxed (and you want to stay in the player) you can use math.randomseed(Time:Millisecs()) 4 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.