Programming involves giving specific instructions but sometimes you want the ability to introduce random behavior. Maybe you want to simulate how a human character sometimes does things in a different order or takes a different path. Or maybe you want the computer to select various items from a collection. Or maybe you want to simulate the randomness of rolling dice. This episode explains how to do this.

Your programming language likely gives you classes or methods to generate random values but while the sequence of values might look random, they’re actually pseudo-random. If you use the same seed value to start the sequence in two different random number generators that are each using the same techniques to generate random numbers, then you’re going to get the same sequence.

This could lead to your customer playing a great first game but then getting bored because the same things happen each time. You really want to use different seeds when using random numbers to determine the computer’s responses to the player’s actions.

But if you’re also using random numbers to generate your world details, then you might actually want the same seed to be used so that the world is the same when the player restarts the same game.


What's on your mind?
On a scale of 0 to 10, how likely are you to refer us to friends?