Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there another way to generate a random number?

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

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.