Skip to content

Random function from WMath is biased #2467

Closed
@lesept777

Description

@lesept777

As coded below in Math.cpp, the random number is biased

long random(long howbig)
{
if(howbig == 0) {
return 0;
}
return esp_random() % howbig;
}

esp_random provides a 32 bit random integer so a number between 0 and 4294967295.
Returning a modulo number is biased. For example if howbig is 100, then all numbers between 0 and 95 have the same probability but numbers between 96 and 99 have a lower probability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions