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

chaos scroll fix #261

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ server:
USE_ENHANCED_CRAFTING: false #Apply chaos scroll on every equip crafted.
SCROLL_CHANCE_ROLLS: 1 #Number of rolls for success on a scroll, set 1 for default.
CHSCROLL_STAT_RATE: 1 #Number of rolls of stat upgrade on a successfully applied chaos scroll, set 1 for default.
CHSCROLL_STAT_RANGE: 6 #Stat upgrade range (-N, N) on chaos scrolls.
CHSCROLL_STAT_RANGE: 5 #Stat upgrade range (-N, N) on chaos scrolls.

#Beginner Skills Configuration
USE_ULTRA_NIMBLE_FEET: false #Massive speed & jump upgrade.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tools/Randomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public static long nextLong() {
}

public static int rand(final int lbound, final int ubound) {
return (int) ((rand.nextDouble() * (ubound - lbound + 1)) + lbound);
return ((int) (rand.nextDouble() * (ubound - lbound + 1))) + lbound;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could really use a unit test. I wrote one to test out your change so you might as well just take it:

package tools;

import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class RandomizerTest {

@Test
void randShouldIncludeEntireRange() {
    Map<Integer, Integer> rands = new HashMap<>();

    final int rounds = 100_000;
    for (int i = 0; i < rounds; i++) {
        int randomValue = Randomizer.rand(-5, 5);
        rands.compute(randomValue, (k, v) -> v == null ? 0 : v + 1);
    }

    assertFalse(rands.containsKey(-6));
    assertTrue(rands.containsKey(-5));
    assertTrue(rands.containsKey(-4));
    assertTrue(rands.containsKey(-3));
    assertTrue(rands.containsKey(-2));
    assertTrue(rands.containsKey(-1));
    assertTrue(rands.containsKey(0));
    assertTrue(rands.containsKey(1));
    assertTrue(rands.containsKey(2));
    assertTrue(rands.containsKey(3));
    assertTrue(rands.containsKey(4));
    assertTrue(rands.containsKey(5));
    assertFalse(rands.containsKey(6));
}

}

}
}
Loading