Select Page

In this post, I have listed several methods to generate a random number. However, sometimes you can see people using a random seed to generate one.

### Why need a seed to create a random number?

Quick answer: if you want to have control to the random sequence or let other people to generate the same sequence of random numbers, take a seed.

We should know that a random number generated by computer is based on some algorithm written by programmers. It means that it is not 100% random like the random process that you find in nature. In another word, we call it pseudo-random.

The random generator is somehow complicated, but for demo purposes, I assume that:

$$aRan_{i} = seed + X_{i}.$$

So if you select the same seed, then you can have the same sequence.

### Random seed in Python.

if you run the code , you will always have the same sequence as mine:

### Random seed in C#

And similarly, we have the same sequence :