Jump to content

question about math.random() function


Recommended Posts

Hi, I have a script in which math.random generates a number and I don't want the number I generate to be decodable by the user.
Therefore, if someone has been in a similar situation, could you explain how exactly this function works if I don't use the math.randomseed() function?
Perhaps someone knows what seed is pulled in by default that is used to generate the number?

Thanks in advance for any help!

Link to comment

Hi, think of math.randomseed() like the starting poit of your randomness, the seed, in order to have unpredictable random numbers you have to provide a integer seed to this function and from now on in your script the random numbers will be generated from this seed, like:

This will give you the same results every single time the code is generated

for i = 1, 10 do
	print(math.random());
end

While this will change every single time due to getRealTime().timestamp never returning the same number.

math.randomseed(getRealTime().timestamp);
for i = 1, 10 do
	print(math.random());
end

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...