how to enldlessly generate platforms in random positions

so I am very new to coding in general and I am trying to make a vertically-scrolling endless runner which basically involves jumping onto platforms to stay alive.I want to generate the same platform in three different locations endlessly. I basically copied some code from an article on the internet and then changed it around to try to make it suit my needs. However, when I run my code in the simulator, one platform is generated in the same location and no others appear. Also, when I look at the console, random numbers do appear. here is the code I am using

local function blockgenerate( event )
for a = 1, 1, -1 do
isDone = false

numGen = math.random(3)
local newBlock
print (numGen)
if (numGen == 1 and isDone == false) then
newBlock = display.newImage (“platform.jpg”)
end

if (numGen == 2 and isDone == false) then
newBlock = display.newImage (“platform.jpg”)
end

if (numGen == 3 and isDone == false) then
newBlock = display.newImage (“platform.jpg”)
end

newBlock.name = (“block” … a)
newBlock.id = a

 newBlock.x = (a * 100) - 100
 newBlock.y = groundLevel
 blocks : insert(newBlock)
 end
 end
 timer.performWithDelay (1000, blockgenerate, -1)

thank you very much.

In your example (which I’m guessing is not exactly the code you’re working with), the loop over ‘a’ always takes the value 1 … which then puts the block at a fixed coordinate, (0,groundLevel).  Since all of your blocks are the same jpg image, you might be getting multiple copies placed exactly on top of each other.

E.g. change the newImage calls to newRect and set a different fill color for each and you’ll see the colors change.

In your example (which I’m guessing is not exactly the code you’re working with), the loop over ‘a’ always takes the value 1 … which then puts the block at a fixed coordinate, (0,groundLevel).  Since all of your blocks are the same jpg image, you might be getting multiple copies placed exactly on top of each other.

E.g. change the newImage calls to newRect and set a different fill color for each and you’ll see the colors change.