[SOLVED] How to get random numbers?

Hi Corona Devs,

I have a question that I did not find any answer and so I would like to ask you for some help if possible.

So, what I need is just the following:

How would I get to generate 6 random numbers that can`t be showed repeated (each one must be unique) from a list starting 00~60?

Easy way to go? Some idea? If you do, please, share with me. I would be very happy of it!

Thank you in advance,

Cheers,
Rodrigo.

try this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
local numbers = {}
--populating table with 5 numbers (1-5)
for i =1,5 do
  numbers[i] = i 
end
 
--loop to generate 5 random numbers
for i = 1, 5 do
    -- select random position from the table
    local pos = math.random(1,#numbers)
        local num = numbers[pos]
        print(num)
        --remove the number from table once it is selected
    table.remove (numbers,table.indexOf(numbers, num))
end     

Hi Technowand,

First of: THANK YOU! You`re a genius mate. Ha, ha, ha, 1 shoot - 1 goal! :)

It worked nicely. I have just tweaked it a little for my own needs and it`s doing (printing) very well!

I`ll start to work with it trying to implement and code my "full" idea into something. :)

I`ve appreciated it, really.

PS: I`ve noted right now that I`ve a copy of your Corona "book" that I bought from you when I`ve started here few months ago. Nice pdf btw...just needing some kind of "UP". :)

Cheers,
Rodrigo.

good to know that it worked... looking forward to see the full idea implemented...
thanks for purchasing the book... yes I know that its past due an update... sorry for that.. was very busy for the last few weeks. will be sitting soon on that... :) for the time if you have any doubts feel free to ask me....

Hey Technowand, no worry. When you get some free time and feel to update something there, that`s good. :)

BTW, thanks one more time and please, feel free to follow me on Twitter if you want - http://twitter.com/RSCdev - as like this the contact can be even more quick. :)

Cheers,
Rodrigo.

@technowand, thanks for function, its awesome

views:1678 update:2012/1/9 8:53:30
corona forums © 2003-2011