Math

Discussion in 'Plugin Development' started by EgyptianKing, Oct 25, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    EgyptianKing

    Okay so I need to come up with a formula that is 100% accurate for my plugin.
    Code:java
    1. String[] parts = plugin.getConfig().getString("Cash.Chicken").split("-");
    2.  
    3. String min = parts[0];
    4. String max = parts[1];
    5.  
    6. float maxAmount = Float.parseFloat(max);
    7. float minAmount = Float.parseFloat(min);
    8.  
    9. double cash = Math.random() * maxAmount;
    10.  
    11. if(cash < minAmount)
    12. {
    13. cash = minAmount + minAmount * Math.random();
    14. }
    15.  
    16. plugin.econ.depositPlayer(p.getName(), cash);
    17.  


    Okay so Math.Random() = 0 - 0.9999999999

    Let's say I have a range of numbers = 2-3
    2 = min
    3 = max

    cash = math.random() * maxAmount (maxAmount is equal to max, which is equal to 3)

    math.random can generate any random number in between 0 and 1, i cannot control it.
    so essentially cash can be = 0.9 * 3 which is 2.7
    or it can be = 0.1 * 3 which is 0.6.
    0.6 is not in the range of 2-3.

    So that is where:
    if cash is less than minAmount (2), which it was, it was 0.6

    then make cash = ________________________ (I need a formula, the one I use is not 100% accurate)
     
  2. Code:java
    1. Math.random() * (maxAmount - minAmount) + minAmount
     
  3. Offline

    baseman101

    Code:java
    1. Random r = new Random();
    2. int cash = r.nextInt(3-2)+ 2;


    3 is the high value, and 2 is the low value.
     
Thread Status:
Not open for further replies.

Share This Page