0

I have a program used to resolve tied die rolls using a RNG that is recursive and could potentially cause the variables in question to exceed the maximum allowance for a normal integer variable.

Will this cause an error? Will it cause my program to crash?

Here is the code:

//This is the method in question. Everytime it is invoked it multiplies the previous //result of each roll by 100 and adds the result of a 20 sided die using an RNG

public void reRoll(){
    for(int i = 0; i < playerlist.size(); i++){
        playerlist.get(i).initroll = (playerlist.get(i).initroll*100) + Dice.d20();
    }
}

//This is the recursive call to that method. If it receives too many ties, such as when it //is used several million times, it will cause the integer value to expand past its initial //boundaries, potentially causing an error

public void resolveTies(){
    while(checkTies() == true){
        reset();
        reRoll();
        compareGroup();
    }
}

Keep in mind this code isn't fully tested yet, and this is my first time trying to talk shop with an outsider, (self taught) so I hope what I'm saying makes sense.

  • This sums it up nicely:http://stackoverflow.com/questions/3001836/how-does-java-handle-integer-underflows-and-overflows-and-how-would-you-check-fo – CBIII Jul 23 '13 at 05:07
  • This isn't actually recursive, so you know. A recursive function calls itself. http://en.wikipedia.org/wiki/Recursion_(computer_science) – seanmk Jul 23 '13 at 05:09

0 Answers0