What is a random seed?
I’ve gotten questions about how to use random seeds. They come up a lot in discussions of things like Osmos’s fixed level generation, but it can be tricky to jump from knowing they exist to figuring out how to use them.
To understand random seeds, it helps to know how computers generate random numbers. Most random number generators are actually pseudorandom number generators. When computers do an operation, they’re supposed to get the same result every time. That is, they’re deterministic. PRNGs use some clever math to take one number and jump to another number in a way that’s unpredictable.
Thus, the RNGs that we use output a sequence of numbers, each one based on the last one that was generated. A seed is just the starting number.
This can lead to some unexpected technical issues if you try to use a random number generator without considering how they work under the hood. But as a general rule what you want to do is to set the seed at the start of your generation and then use that generator for all of your calculations that need a deterministic, repeatable result.
(I sometimes set up two RNGs: one for the important calculations that other stuff depends on and one for the incidental stuff like randomizing the paths of particles, where no one will notice if they’re not exactly the same.)
Most languages and libraries have their own way of managing randomness. Processing has a randomSeed() function to set the seed, while C# uses the dotNet Random class. Same idea either way.