lundi 29 octobre 2018

generate non duplicate integers in LUA

I am very new in programming in lua

I am trying to generate 5 random non duplicate values between 0,500 and assign them to 5 variables using LUA.

So far I have used the following code which unsuccessfully attempts to generate the random numbers and assigns the values. The problem is:

1 - this code is sometime generating the duplicate numbers 2 - the name which I want to look like x-1, x-2 and so on, prints like x-1, x-12.

Can you please help me with this.

Thanks in advance.

Ed

Example:

v_Name = "x-"
for i =1, 5 do
  X = math.random (0, 500)
  v_Name = v_Name..(i)
  print (v_Name)
  print (X)
 end 




Aucun commentaire:

Enregistrer un commentaire