

What’s a seed in a random number generator?
source link: https://yourbasic.org/algorithms/random-number-generator-seed/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What’s a seed in a random number generator?
In reality pseudorandom numbers aren't random at all. They are computed using a fixed deterministic algorithm.

The seed is a starting point for a sequence of pseudorandom numbers. If you start from the same seed, you get the very same sequence. This can be quite useful for debugging.
If you want a different sequence of numbers each time, you can use the current time as a seed.
Example
This generator produces a sequence of 97 different numbers, then it starts over again. The seed decides at what number the sequence will start.
// New returns a pseudorandom number generator Rand with a given seed.
// Every time you call Rand, you get a new "random" number.
func New(seed int) (Rand func() int) {
current := seed
return func() int {
next := (17 * current) % 97
current = next
return next
}
}
func main() {
rand1 := New(1)
fmt.Println(rand1(), rand1(), rand1())
rand2 := New(2)
fmt.Println(rand2(), rand2(), rand2())
}
17 95 63 34 93 29
The random number generators you’ll find in most programming languages
work just like this, but of course they use a smarter function.
Ideally, you want a long sequence with good random properties
computed by a function which uses only cheap arithmetic operations.
For example, you would typically want to avoid the %
modulus operator.
Share:
Recommend
-
64
ephemerand ephemerandis an experimental approach to generating a globally-consistent randomness beacon. Once every day, the US military takes various measurements of the satellites in the
-
127
Fake US Telephone Numbers, United States Tired of giving out your mobile number all over the internet and getting spammed all day long by advertisers? Stay calm, we have a solution for you: a fake number. If you are at...
-
11
Hardware random number generator From Wikipedia, the free encyclopedia Jump to navigation
-
9
Ensuring Randomness with Linux's Random Number Generator 10/03/2013
-
9
The Problem I was working on a system where I had to initialize each microcontroller-based device on a communication bus with unique addresses. Since the addressed are supposed to be unique while the devices were identical, the tric...
-
6
Secure development: New and improved Linux Random Number Generator ready for testing John Leyden
-
11
Today we're going to build out a random number generator using JavaScript. Random number generators are a fantastic beginner JavaScript project. You get to work with some of the important basics while creating something that serves an actual...
-
10
Random number generator enhancements for Linux 5.17 and 5.18Random number generator enhancements for Linux 5.17 and 5.18by Jason A. Donenfeld (zx2c4), 2022-03-17The random number generato...
-
6
Linux Random Number Generator Sees Major Improvements Become a fan of Slashdot on Facebook ...
-
5
[Golang] Seed Pseudorandom Number Generator (PRNG) Properly March 21, 2017 In my...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK