Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there another way to generate a random number?

Asked by 8 years ago

math.random keeps giving me the exact same numbers each time I click 'test'. Is there a way to solve this so I get a different end number or another way of doing it?

for x = 1, 9 do i = math.random(1, 2000) print(i)

I get the same result each time.

2 answers

Log in to vote
1
Answered by 8 years ago

Set the randomseed
Just not before every loop

ROBLOX servers don't set the randomseed properly, but setting the randomseed several times in a script will make random produce very similar results because the numbers are so close together.

math.randomseed(os.time()) -- At the top of a script using math.random
Ad
Log in to vote
0
Answered by
Prioxis 673 Moderation Voter
8 years ago

You could write a table with all the possible combinations you'd want like

local num = {1,2,3,4,5,6,7,8,9,10}
local t = num[math.random(1, #num)]

and then you could have another table that would store the already chosen values and check to see if the value has already been chosen (probably the more logical route since your working with 1,2000)

Answer this question