Class Chance

java.lang.Object
dev.sefiraat.sefilib.misc.Chance

public final class Chance extends Object
This class contains basic utility methods for chance and rolls.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    roll(double upper)
    Rolls a number starting from 1 to upper
    static double
    roll(double upper, boolean upLimit)
    Rolls a number starting from 1 to upper
    static int
    roll(int upper)
    Rolls a number starting from 0 to upper
    static int
    roll(int upper, boolean upLimit)
    Rolls a number starting from 1 to upper
    static boolean
    testChance(double chance)
    Tests a chance roll starting from 1 to upper
    static boolean
    testChance(double chance, double upper)
    Tests a chance roll starting from 1 to
    static boolean
    testChance(int chance, int upper)
    Tests a chance roll starting from 1 to upper

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • testChance

      public static boolean testChance(double chance)
      Tests a chance roll starting from 1 to upper
      Parameters:
      chance - The chance to succeed between 0-1
      Returns:
      true if roll passes
    • testChance

      public static boolean testChance(int chance, int upper)
      Tests a chance roll starting from 1 to upper
      Parameters:
      chance - The number the roll must be lower than
      upper - The highest possible number that could roll (inclusive)
      Returns:
      true if roll passes
    • roll

      public static int roll(int upper, boolean upLimit)
      Rolls a number starting from 1 to upper
      Parameters:
      upper - The highest possible number that could roll (inclusive)
      upLimit - If true, the bound will be increased for 1 for inclusivity while maintaining readability for manually typed numbers (i.e. Upper 50 converts to 51 returning a max of 50 still). Set false when using 0 based indexes (list.size())
      Returns:
      rolled int
    • testChance

      public static boolean testChance(double chance, double upper)
      Tests a chance roll starting from 1 to
      Parameters:
      chance - The number the roll must be lower than
      upper - The highest possible number that could roll (inclusive)
      Returns:
      true if roll passes
    • roll

      public static int roll(int upper)
      Rolls a number starting from 0 to upper
      Parameters:
      upper - The highest possible number that could roll (inclusive)
      Returns:
      rolled int
    • roll

      public static double roll(double upper)
      Rolls a number starting from 1 to upper
      Parameters:
      upper - The highest possible number that could roll (inclusive)
      Returns:
      rolled int
    • roll

      public static double roll(double upper, boolean upLimit)
      Rolls a number starting from 1 to upper
      Parameters:
      upper - The highest possible number that could roll (inclusive)
      upLimit - If true, the bound will be increased for 1 for inclusivity while maintaining readability for manually typed numbers (i.e. Upper 50 converts to 51 returning a max of 50 still). Set false when using 0 based indexes (list.size())
      Returns:
      rolled int