Skip to content
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

Correct calculation of random distribution in openPlatonic #235

Open
vinniefalco opened this issue Dec 11, 2020 · 0 comments
Open

Correct calculation of random distribution in openPlatonic #235

vinniefalco opened this issue Dec 11, 2020 · 0 comments

Comments

@vinniefalco
Copy link

I believe this algorithm is correct, and runs in constant average time

void openPlatonic( int amount, int* blessings )
{
    std::random_device rd;
    double const weights[] = {
        13200.0, 13200.0, 13200.0, 13200.0,
        396.0, 1.0, 1.0, 1.0, 1.0 };
    double sum = 40000.0;
    for( int i = 0; i < 8; ++ i)
    {
        int n = std::binomial_distribution<int>(
            amount, weights[i] / sum)(rd);
        blessings[i] += n;
        amount -= n;
        sum -= weights[i];
    }
}

It would need to be ported from C++ to JS, including an implementation of binomial_distribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant