Skip to content

Helpers.cpp functions can produce non-uniformity #1

Open
@ryandougherty

Description

@ryandougherty

double rand_float()
{
return rand() / (static_cast(RAND_MAX));
}

double rand_float(float min, float max)
{
return (max-min)*rand_float()+min;
}

int rand_int(int min,int max)
{
return (rand() % (max-min)) + min;
}

These functions in /simplega/helpers.cpp can give non-uniformity because of modding by an integer (see http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful for details as to why).

Proposition: use std::uniform_int_distribution and std::uniform_real_distribution to shape the random integers/floats being generated.

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