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

Underground fluids: non-zero MinAmount heavily skews effective maximum #1569

Open
MauveCloud opened this issue Oct 11, 2020 · 1 comment
Open

Comments

@MauveCloud
Copy link
Collaborator

In a recent playthrough (playing locally, not on a server), I decided to be more generous with the overworld oil, setting it to minimum 100 and maximum 6250 for each type (as opposed to 0-625 default), and the first oil drilling rig I set up got me 10885 L of light oil per cycle. That's running at MV, so presumably the base rate was actually 21770 L/cycle, way above the maximum I set in the config.

I tried separately testing the algorithm from

public int getRandomAmount(Random aRandom){//generates some random ass number that correlates to extraction speeds
int div = (int)Math.floor(Math.pow((MaxAmount-MinAmount)*100.d*DIVIDER, 0.2d));
int min = (int)Math.floor(Math.pow(MinAmount*100.d*DIVIDER, 0.2d));
double amount = min+aRandom.nextInt(div)+aRandom.nextDouble();
return (int) (Math.pow(amount, 5) / 100);//reverses the computation above
}
and found that configuring for 100-6250 actually produces output of around 91-35241. The default 0-625 config produces output of 0-624, which is close enough. However, just changing the minimum to 1 shifts the output to 0-1831.

@MauveCloud
Copy link
Collaborator Author

I don't really understand why the current method is using the min and max to calculate a parameter for the nextInt function, but the failure when MinAmount is non-zero is probably related to the Binomial Theorem. I tried a few alternatives, and I think something like this will have the desired distribution and handle the min and max correctly:

    public int getRandomAmount(Random aRandom){
        int range = (int) Math.floor((MaxAmount - MinAmount) * DIVIDER);
        int min = (int) Math.floor(MinAmount * DIVIDER);
        int mult = (int)1e6;
        double result = min + Math.pow(aRandom.nextInt(mult), 5) * range / Math.pow(mult, 5);
        return (int)result;
    }

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