Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cmaglie opened this issue Nov 15, 2012 · 2 comments
Closed

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

cmaglie opened this issue Nov 15, 2012 · 2 comments
Labels
Component: Core Related to the code for the standard Arduino API
Milestone

Comments

@cmaglie
Copy link
Member

cmaglie commented Nov 15, 2012

This is Issue 575 moved from a Google Code project.
Added by 2011-08-05T07:31:16.000Z by rob.till...@gmail.com.
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

@RobTillaart
Copy link

Saw that this issue is still open in 1.0.3 while easy to fix.
Is there a reason for that?

@facchinm
Copy link
Member

Fixed by #3202

@ffissore ffissore added this to the Release 1.6.5 milestone May 28, 2015
@per1234 per1234 added the Component: Core Related to the code for the standard Arduino API label May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Related to the code for the standard Arduino API
Projects
None yet
Development

No branches or pull requests

6 participants