So there are many fancy algorithms out there for generation. But I'll try to make a simple one work.
First you're going to want to randomly place your objects (planets and stuff) in your infinite level. There is your first problem, you cannot simply write 'Set Position (random(-8, 8), random(-8, 8))' since 8 is not a number. So what you could do is generate it relative to something else, the spaceship for example. You could give the spaceship 4 instance variables, maxX, maxY, minX and minY which represent how far the ship has travelled in any direction and when it get close to one of its boundries, simply generate more planets with say random(maxX + 100, maxY + 100) or something similar. So the universe is procedurally generated. This method is still not ideal as if done right it will take a lot of processing power the more the ship travels, and if done wrong will leave you with huge patches of empty space.
Now I don't know if you've ever played Minecraft, but we can learn something from its procedural generation methods. You can split your infinite universe into an infinite number of 'chunks' with finite volumes. When the ship gets close to ungenerated chunks it generates those chunks. You will need to store these chunks in an array and load them and unload them as you see fit. NOTE: Having too many objects loaded at a time will cause performance problems. You can create a variable called render distance, which takes an integer larger than that of half the screen, maybe double that. Then you can set up an equation for a circle using this render distance as a value. If any chunks fall into this circle load them (if they do not exist generate them), if there are chunks outside of this circle save them and remove them.
Generating a chunk
Say you want 2 planets in every 200 square pixels you can make your chunks the size of 200x200, then when you require to generate the chunk from the above method you can simply spawn 2 planets at any coordinates between 0 and 200 for both x and y. To place the planets properly the coordinates would be chunk.minX + genX and chunk.minY + genY. So the planets are only positioned relative to the chunk. The chunk has finite coordinates which can be assigned incrementally.
Then you can have different types of chunk etc to have variety where the generation properties are different and then conditions about where they can spawn etc. It depends on what level of complexity you want.
I hope this garbled explanation helps in some way.