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?
I found this seeded random number generator for Javascript and noticed that many devs use it.
Math.random
?For further actions, you may consider blocking this person and/or reporting abuse
Balraj Singh -
Hanzla Baig -
Yan Levin -
Shane Wen -
Top comments (7)
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.Thank you.
What do you mean by one-sided dice? Only one side? One number? I didn't get it.
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.
Owh, got it. Thank you. Awesome two cents. :)
Hi @supunkavinda , @captainsafia wrote a really good explanation on how random numbers work and how they are useful. This might interest you:
Random numbers, revealed
Safia Abdalla ・ Jan 15 ・ 3 min read
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!
Thank you very much. I bookmarked the tutorial. I'll read it soon. :)
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.