itsanjan / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

randomSeed should have unsigned long as parameter #575

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
OBSERVATION
------------
Wmath.cpp / Wprogram.h have defined randomSeed as

void randomSeed(unsigned int seed)
{
  if (seed != 0) {
    srandom(seed);
  }
}

while the avrlib defines - void srandom (unsigned long __seed);

This means loss of 2^32 -2^16 possible seeds to randomize.

PROPOSAL
--------

If you accept 0 as a valid seed you can rewrite it to: 

#define randomSeed(s) srandom(s)

otherwise

void randomSeed(unsigned long seed)
{
  if (seed != 0) srandom(seed);
}

See - http://arduino.cc/forum/index.php/topic,66206.msg505310.html#msg505310

// using windows 7/64 IDE 22

Original issue reported on code.google.com by rob.till...@gmail.com on 5 Aug 2011 at 7:31