I want to develop a procedural galaxy / starfield generator.
A rather simple approach would be to use some pseudo-random algorithm to repeatedly create a star and its properties (such as position, mass, luminosity, density, and so on...). But in doing that, I would be quite limited in terms of the total number of stars. They would all be created at startup, and kept in memory, even the ones which are totally out of the player's range.
I do not want to end up with millions of star instances.
What I need is some way to only generate the stars which are near to the player and, therefore, being rendered. On the other side, I want the player to be able to return to stars, once they disappear due to being too far away. Take Space Engine for example, it also does not generate all its trillion stars at the start of the simulation.
What would be a suitable approach to this kind of problem?