## DEV Community is a community of 865,621 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Supun Kavinda

Posted on

# [Question] What is random seed?

I found this seeded random number generator for Javascript and noticed that many devs use it.

• What is random seed number?
• How does it differ from Javascript's `Math.random`?
• Why is it useful?

## Discussion (7)

Jérémie Astor

I'll just give my two cents:
Random number generators in computer science are like a one sided dice, the seed setting the start face.
It is useful because you can replay the random sequence.
I don't know javascript so I can't tell the difference with `Math.random`, yet I suppose there has to be a seed somewhere.

Supun Kavinda

Thank you.

What do you mean by one-sided dice? Only one side? One number? I didn't get it.

Jérémie Astor

I felt the wording was wrong ;-)
Another try: it plays a sequence that looks random, but is actually, well, a sequence. Like a dice that does not fall on its sides 'cause it has no sides.

Supun Kavinda

Owh, got it. Thank you. Awesome two cents. :)

rhymes

Hi @supunkavinda , @captainsafia wrote a really good explanation on how random numbers work and how they are useful. This might interest you:

Related to that library, I think it's just an alternative implementation of a pseudorandom number generator.

They are called "pseudorandom" because the initial value, the seed, determines the result, so they are not truly random.

Hope this helps!

Supun Kavinda

Thank you very much. I bookmarked the tutorial. I'll read it soon. :)

Ryan Latta

As noted by other people, Random number generators are pseudo-random which means they look random.

They all use a "seed" to set the numbers that will appear. Put the same seed in and you'll see the same numbers.

This is really important for two things. First is security and second is testing.

Security often demands a secure generator because if someone malicious can guess the seed they can replay randomness which often a core part of security measures regarding tokens. Once they can replay the numbers they can work the rest.

Testing is the other major benefit a seed provides. If you were coding a thing to simulate dice rolls you would likely want to fix some of the results to confirm things. Pre-defined seeds help with that.