0 votes

Is there a Class/methods to have multiple independent random number generators each initialized with separate seeds?

This is useful for example when needing to use random numbers but be able to reproduce the same result next time. (Ex. 'world seed' for a prodcedurally generated world)

in Engine by (254 points)

1 Answer

+1 vote
by (5,240 points)

Oh, I see ... so I pass the seed that is returned back back into rand_seed to get the next random number and so on?

What is the range and type of the returned random number?

OK, so I've tried it and the value returned is always a largish integer. Since I don't know the possible range of the integer, then I can't use it.

Use seed(int value) to set the seed and then use rand(float from, float to) so that you can get a specific range. If you need it to be an integer, use round(float value) on the value that rand returned.

If that way doesn't work, you can take the large integer value you were getting and use fmod(randomnum, maxvalue_possible). This will make it so that the number returned cannot be larger than you want.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.