What's the best way to make and reuse random numbers?
here's my current code
I'd like a way to do these in loops so they can generate infinitely, but I can't find out how
Pipes? Sounds like Flappy Bird style game?
As usual, it is hard to give any advice without knowing any details.
If it is a Flappy Bird style game check the existing projects.
For a quick overview, normally each Pipe is created as an object with its own start values (random start position).
Once the Pipe leaves the screen it destroys itself and triggers the creation of a new Pipe.
For sure the details are a little bit more complex than that, check existing examples.
Live Long and Tinker
P.S. if my guess was wrong it is always a good idea to add a link to your game to the question.
Publish it ( unlisted) and post the link from the Publish page
This is written without checking, but it's more or less what you are asking about:
for i = 0 to 6
for i=0 to 6
drawPipe(-200 + i*200,rndNumbers[i])
create a class that has the x and y rechanges by a function called
set_Last, but you need a camera left side point for this.
init = function()
pipe = class
constructor = function(_x, _y)
set_Last = function(_x, _y) // this function is generally called by the pipes manager
this.x = _x
this.y = _y
pipeSpacing = 100 // any number
maxValueY = 120 // same ^^
maxValueX = 0
pipeManager = object
pipes = 
init = function(_numberofPipes)
for _index = 0 to _numberofPipes
this.pipes.push(new pipe(_index * pipeSpacing, this.getRandomY())
maxValueX = max(maxValueX, this.pipes[_index].x)
getRandomY = function() return random.nextInt(maxValueY) - maxValueY / 2 end
update = function()
for _pipe in this.pipes
if _pipe.x > camera.leftSidePoint then // where the camera here must be defined and you have the left side point
_pipe.set_Last(maxValueX + pipeSpacing, getRandomY())
maxValueX = _pipe.x
// add your draw function as for loop
You just have to init the pipeManager, update it, and draw it. Don't forget to add