How would I set multiple values with math.random without repeated numbers?

Say if I were to create a row of random numbers, like this.

local RowOne = script.Parent

RowOne.OneNumber.Value = math.random(1, 75)

RowOne.TwoNumber.Value = math.random(1, 75)

RowOne.ThreeNumber.Value = math.random(1, 75)

RowOne.FourNumber.Value = math.random(1, 75)

RowOne.FiveNumber.Value = math.random(1, 75)

How would I do this without repeated results?

4 Likes

I’ve changed your post’s category to #help-and-feedback:scripting-support, the Cool Creations category is to show off your creations/gather feedback. You should also format your code to make it more readable, for more information see the category guidelines.

1 Like
local RowOne = script.Parent

RowOne.OneNumber.Value = math.random(1, 75)

RowOne.TwoNumber.Value = math.random(1, 75)

RowOne.ThreeNumber.Value = math.random(1, 75)

RowOne.FourNumber.Value = math.random(1, 75)

RowOne.FiveNumber.Value = math.random(1, 75)

Its just your code but formatted.

The good way to do that is using array tables

Create a map containing all used numbers then check from it when you generate a new number.

local used = {}

local function random(lower, upper)
    local number = math.random(lower, upper)

    repeat
        number = math.random(lower, upper)
    until (not used[number])

    used[number] = true

    return number
end
12 Likes

Thanks for your help! I appreciate it.

2 Likes
local NUMBERS = {}
local LastChoosen

for i = 0,6 do
	wait()
	local Range = math.random(1, 75)

	if LastChoosen ~= Range then
		NUMBERS[i] = Range
		i = i + 1
	end
	
	LastChoosen = Range
end

try this out.

2 Likes

afaik you cant change the value of i from inside the loop.

Wait it isnt working what to do. Where do I put the numbers