Reference.RandomSeed History

Show minor edits - Show changes to markup

February 08, 2008, at 05:20 PM by David A. Mellis -
Deleted line 35:
September 27, 2007, at 02:56 PM by David A. Mellis - millis() isn't random if there's no human intervention.
Changed lines 6-7 from:

If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin, or read the time by calling millis().

to:

If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin.

Added line 23:
  randomSeed(analogRead(0));
Deleted line 26:
  randomSeed(analogRead(0));
September 27, 2007, at 06:08 AM by Paul Badger -
Changed lines 6-7 from:

If it is important for a sequence of values generated by random() to differ on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin, or read the time by calling millis().

to:

If it is important for a sequence of values generated by random() to differ, on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin, or read the time by calling millis().

September 27, 2007, at 06:05 AM by Paul Badger -
Changed lines 4-5 from:

randomSeed initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. This sequence, while very long, and random, is always the same.

to:

randomSeed() initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. This sequence, while very long, and random, is always the same.

September 27, 2007, at 06:04 AM by Paul Badger -
Changed lines 6-7 from:

If it is important for sequence of values generated by random() to differ on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin, or read the time with millis().

to:

If it is important for a sequence of values generated by random() to differ on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin, or read the time by calling millis().

September 27, 2007, at 06:03 AM by Paul Badger -
Changed lines 4-5 from:

randomSeed initializes the pseudo-random number generator, which helps it to generate "random" numbers. There are a variety of different variables you can use in this function. Commonly used are current time values (using millis() ), but you could also try something else like user intervention on a switch or antennae noise through an analog pin.

to:

randomSeed initializes the pseudo-random number generator, causing it to start at an arbitrary point in its random sequence. This sequence, while very long, and random, is always the same.

If it is important for sequence of values generated by random() to differ on subsequent executions of a sketch, use randomSeed() to initialize the random number generator with a fairly random input, such as analogRead() on an unconnected pin, or read the time with millis().

Conversely, it can occasionally be useful to use pseudo-random sequences that repeat exactly. This can be accomplished by calling randomSeed() with a fixed number, before starting the random sequence.

Changed line 22 from:
  Serial.begin(19200);
to:
  Serial.begin(9600);
Added lines 29-30:
  delay(50);
September 27, 2007, at 05:56 AM by Paul Badger -
Changed lines 4-5 from:

This allows you to place a variable into your random number generator, which helps it to generate "random" numbers. There are a variety of different variables you can use in this function. Commonly used are current time values (using millis() ), but you could also try something else like user intervention on a switch or antennae noise through an analog pin.

to:

randomSeed initializes the pseudo-random number generator, which helps it to generate "random" numbers. There are a variety of different variables you can use in this function. Commonly used are current time values (using millis() ), but you could also try something else like user intervention on a switch or antennae noise through an analog pin.

May 27, 2007, at 02:33 AM by Paul Badger -
Deleted lines 30-32:
May 08, 2007, at 07:22 PM by David A. Mellis -
Deleted line 14:

int time;

Changed lines 22-23 from:
  time = millis();
  randomSeed(time);
to:
  randomSeed(analogRead(0));
Changed line 24 from:
  Serial.println(r);
to:
  Serial.println(randNumber);
September 18, 2006, at 05:04 PM by Jeff Gray -
Changed lines 4-5 from:

This allows you to place a variable into your random number generator, which helps it to generate "random" numbers. There are a variety of different variables you can use in this function. Commonly used are current time values (using millis(), but you could also try something else like user intervention on a switch or antennae noise through an analog pin.

to:

This allows you to place a variable into your random number generator, which helps it to generate "random" numbers. There are a variety of different variables you can use in this function. Commonly used are current time values (using millis() ), but you could also try something else like user intervention on a switch or antennae noise through an analog pin.

September 11, 2006, at 04:59 PM by Jeff Gray -
Changed lines 1-2 from:

randomSeed(long seedValue)

to:

randomSeed(seed)

Changed lines 7-8 from:

long - pass a number to generate the seed.

to:

long, int - pass a number to generate the seed.

September 11, 2006, at 04:57 PM by Jeff Gray -
Added lines 1-35:

randomSeed(long seedValue)

Description

This allows you to place a variable into your random number generator, which helps it to generate "random" numbers. There are a variety of different variables you can use in this function. Commonly used are current time values (using millis(), but you could also try something else like user intervention on a switch or antennae noise through an analog pin.

Parameters

long - pass a number to generate the seed.

Returns

no returns

Example

int time;
long randNumber;

void setup(){
  Serial.begin(19200);
}

void loop(){
  time = millis();
  randomSeed(time);
  randNumber = random(300);
  Serial.println(r);
}

See also

Reference Home

Share