How to check if a number has been already used in math.random?
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!
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?