# randomizing for, do

so i have been trying to make a game that generates a random map that is just 2d, and basically just want to have bricks made across the screen. Using

distance = 100
for z = 1, 100 do
rect(z * distance,100, 100,100)

I can make a flat landscape with no gaps, but on higher up sections of the screen I want to have bricks only in certain area to make the landscape more rugged. I have tried using

distance = math.random(100,1000)

before the for, do statement, but it just makes the bricks generate in the same spot then move away from each other. Does anyone know how to make it so the the bricks are a random distance from each other, but not the same random distance either, a different distance between each brick? Really stuck, having trouble. Help appreciated.

@ SkyTheCoder ?

@jrohanian This isn’t close to being optimized, but just thrown together to see if this is what you’re after.

EDIT: Added code to allow horizontal scrolling. Just drag your finger left or right.

EDIT: Modified code again.

``````
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
spriteMode(CORNER)

function setup()
tab={}
size=5000
dx=0
h=8
l=1
for z=-size,size,30 do
tab[z]=math.random(l,h)
l=tab[z]-3
if l<1 then
l=1
end
h=tab[z]+3
if h>10 then
h=10
end
end
end

function draw()
background(40,40,50)
for x=-size,size,30 do
for z=1,tab[x] do
sprite("Platformer Art:Block Brick",x+dx,30*z,30)
end
end
end

function touched(t)
dx=dx+t.deltaX
end

``````