RandomSeed()

From Microduino Wiki
Revision as of 06:01, 16 August 2016 by Fengfeng (talk) (Created page with "randomSeed(seed) *'''Description''' Use randomSeed() to initiate pseudo random number generator, to make the generator start from an arbitrary point in the random sequence, w...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

randomSeed(seed)

  • Description

Use randomSeed() to initiate pseudo random number generator, to make the generator start from an arbitrary point in the random sequence, which is very long, random, and it is always the same sequence.

If you need a truly random number to be generated in a random() sequence, you can use randomSeed() to preset an absolute random input when its subsequence is being executed. For example, the returned value of function analogRead() on a disconnected pin.

On the other hand, sometimes the accurate repeat of the pseudo random number is also useful. So before the start of a random sequence, it can be completed through calling a randomSeed() with fixed numbers.

  • Parameter

long,int - Generate seeds through numbers.

  • Return

No returned values.

  • Example

long randNumber;
 
void setup(){
  Serial.begin(9600);
  randomSeed(analogRead(0));
}
 
void loop(){
  randNumber = random(300);
  Serial.println(randNumber);
 
  delay(50);
}

[Return to Arduino Syntax Manual]