Hey @ollie.brown. This is a very very simple task, it’s called shuffling. Just like you would shuffle a deck of cards.
local function shuffle(t)
local iterations = #t
local j
for i = iterations, 2, -1 do
j = random(i)
t[i], t[j] = t[j], t[i]
end
end
local numbers = {}
for i = 1, 56 do
numbers[i] = i
done
shuffle(numbers)
Now you have an array of numbers that are randomized. If you want to show 6 then:
local balls = {}
for i = 1, 6 do
balls[i] = display.newImageRect(string.format("images/balls%02d.png",i), 64,64)
-- rest of the code to display the balls
end
That last bit makes a few assumptions, first your ball graphics are in a folder called “images” and that each ball is named ball01.png, ball02.png, etc. and that they are 64x64 in size. You of course would substitute whatever you oneed for that. The point was to show you that you would just pick off the first X number of balls after you shuffled the array.
[import]uid: 19626 topic_id: 28868 reply_id: 116329[/import]