Skip to content

Helpers.cpp functions can produce non-uniformity #1

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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