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 :


Follow me

Tung Nguyen

PhD/Researcher/Programmer at Up Education - YooBee Colleges
I received the B.Eng. Degree in telecommunication from Shanghai University, MSc of the same major from Paris-Sud University and a PhD degree in Computer Science from Auckland University of Technology. My research interests include machine learning, game theory, computational trust, multi-agent systems and software engineering.
Follow me

Latest posts by Tung Nguyen (see all)

Login with your social ID or Credentials