Math.random excluding

So I have this keypad which you need 5 pieces of information to solve. Usually, for everyone 1 keypad there will be (in this case) 5 pieces of information + 1. So there will be 6 possible spots a piece of the keypad will be. So i want to assign every piece of information to 1 place, but when I use math.random(1,6), more likely than not, the same place will hold 2 pieces of info. Is there a way i can exclude a number when doing math.random so every time i do math.random it will be between numbers which havent already been picked?

(What I’ve done is for every keypad there are x string values and each string value has the name of a place in the workspace.)

you can just add the already used numbers to a table and reroll if the mathrandom rolls something that is already in the table

As CZXPEK said, you could store the already used numbers and then repeat the rolling until it gets a new number.

Alternatively, you could store the locations in a table, which you then remove the locations from when they are picked

e.g.

local Locations = {...} -- Set this

function GetLocationsExample()
    local Possible = table.clone(Locations)
    
    local Index1 = math.random(#Possible)
    local Chosen1 = Possible[Index1] -- This is the first location
    table.remove(Possible, Index1)

    local Index2 = math.random(#Possible)
    local Chosen2 = Possible[Index1] -- This is the second location
    table.remove(Possible, Index2)
end

You can adjust the script to make use of for i = 1, 5 and stuff depending on how you have your game setup or personal preference. You can keep adding more index things, the 2 included are just examples.