Skip to content

randomSeed should have unsigned long as parameter [imported] #575

@cmaglie

Description

@cmaglie

This is Issue 575 moved from a Google Code project.
Added by 2011-08-05T07:31:16.000Z by [email protected].
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium

Original description

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 - https://forum.arduino.cc/t/the-reliable-but-not-very-sexy-way-to-seed-random/65872/38

// using windows 7/64 IDE 22

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CoreRelated to the code for the standard Arduino API

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions