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

How to check if a number has been already used in math.random? [closed]

Asked by
AxeI_cALT -78
4 years ago

How to check if a number has been already used in math.random?

Closed as Not Constructive by JesseSong

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
8oe 115 Donator
4 years ago

Hey there.

I believe you are looking to go through numbers using math.random.

My best suggestion is using an arrays and storing the numbers in it.

Therefore after each number store it in the array and go on.

local myarray = {}
local x = 0
local max = 5

repeat
    local y = math.random(1,max)
    if not myarray[y] then
        print(y)
        table.insert(myarray, y, y)
        x = x + 1
    end
until x == max

In the code above it is going through numbers 1, 2, 3, 4, and 5.

We are putting the information in an array to not repeat these numbers.

Then we are printing the numbers.

This may have not been 100% the most efficient way but I hope this helps!

0
Tranks that's exactly what I needed! AxeI_cALT -78 — 4y
0
when you use not myarray[y] you're checking for index y in the table rather than the number Robowon1 323 — 4y
Ad