Jump to content

How to generate random x value from a given Seed ?


Slastraf
 Share

Recommended Posts

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.

  • Upvote 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...