Skip to content

randomSeed: Bad/redundant "if"  #3887

Open
@igendel

Description

@igendel

Hi,

In function randomSeed (WMath.cpp, line 30) there's the code

  if (seed != 0) {
    srandom(seed);
  }

Since "srandom" handles the value 0 itself (see for example its implementation in random.c of AVR-Libc*), it seems there's no need for that "if". Furthermore, it is undocumented and may break functionality - for instance, if a user wants to produce two identical pseudo-random sequences using the seed 0.

If that "if" can be removed, it will save a byte or two.

See discussion about this here (not all of it directly relevant): https://forum.arduino.cc/t/randomseed-why-is-0-ignored/337424

Thanks,

Metadata

Metadata

Assignees

Labels

Component: CoreRelated to the code for the standard Arduino APIType: Bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions