Can randomSeed have any 16 bit number passed to it? Or should I avoid giving it 0?
What happens if you use 0? Have you tried it? If I recall correctly the function does not accept 0. You could check the code, I think it makes the value a bit to predictable. By avoiding zero one forces edge user to choose.
Zero is ignored by randomSeed. Passing a zero leaves the seed value unchanged.
The analog pins produce seemingly random values when floating (no pull up/pull down resistors), and that is why you'll see randomSeed(analogRead(A0)); in some codes. It will/should create different results each time you call it, so your numbers look more random. I wouldn't bother passing it any specific number (e.g. randomSeed(5)), as the numbers random() produces would be the same sequence each time. Therefore, there would be no need to call it at all if you pass it the same number each time. IMO, the analog method works well; I would use that, and not bother worrying about what number you pass to it.
Onions.
It
will/shouldcreate different results each time you call it
...may or may not...
...had better... [FTFY]. If passing the same random seed does not cause the RNG to generate the same sequence, then the Arduino generator is downright broken. It's a PRNG, which by its nature is supposed to be deterministic (as odd as that sounds): see Pseudorandom number generator - Wikipedia
I shall avoid the urge to drag out my soapbox on this issue ![]()
The Park–Miller random number generator is used in AVR Libc. It is well documented and a good choice. For any given valid seed, the generator produces the same sequence.
This...
randomSeed( analogRead( A0 ) );
...can, under the right conditions, be exactly the same as this...
randomSeed( ARBITRARY_CONSTANT );
In other words, this is not always true...
The analog pins produce seemingly random values when floating
Was reading Wikipedia about a 'infamous' RNG developed by IBM in the 60s. Short story it had 'problems' but the following quotes at the end of the article was kind of interesting:
…its very name RANDU is enough to bring dismay into the eyes and stomachs of many computer scientists!
—Donald Knuth, [4]One of us recalls producing a “random” plot with only 11 planes, and being told by his computer center’s programming consultant that he had misused the random number generator: “We guarantee that each number is random individually, but we don’t guarantee that more than one of them is random.” Figure that out.
—W. H. Press et al, [3]
Many of my projects include an audio input line from my computer so when I use randomSeed I pass an analogRead for whatever pin that is on because it is constantly changing and I don't have to worry about leaving one floating or whatever