Alright, so I am simulating a rice roll 100 times, repeatedly.
It's getting some whack numbers for some reason, I can't find the problem in code. I have done some printing of the different variables and it seems fine, but I know theres something wrong.
package com.github.geodox.dicerollingstats.main;
import java.util.Arrays;
import java.util.Random;
/**
* @author GeoDoX
*
* RollingStats.java
*/
public class RollingStats
{
private static Random rand; //Used for generating the roll
private static int[] rolls; //Stores the roll counts
private static int[] highestRolls; //Stores the highest roll counts
public static void main(String[] args)
{
rand = new Random();
rolls = new int[6]; //new int array of size 6
highestRolls = new int[6]; //new int array of size 6
rollConsec();
}
private static int[] roll()
{
for(int i = 1; i <= 100; i++) //Roll 100 Times
{
int diceValue = rand.nextInt(6) + 1; //Generate number between 1 - 6
rolls[diceValue - 1] = rolls[diceValue - 1] += 1; //Add 1 to the Array at the index of the roll
}
return rolls;
}
private static void rollConsec()
{
while(true) //Keep repeating
{
int[] tempArray = roll();
int currHighest = 0; //Value to store the highest number;
int highestIndex = 0; //Value to store the highest index, 1 - 6
for(int i = 1; i < 6; i++) //Get highest index
{
int currValue = 0;
currValue = tempArray[i]; //Set currValue equal to the value at i
if(currValue > currHighest) //Check if currValue is higher then the currently highest
{
currHighest = currValue; //If it is, set the highest to the current value
highestIndex = i; //Set the highest index to i
}
}
highestRolls[highestIndex - 1] = highestRolls[highestIndex - 1] += 1; //Add 1 to the highest index, represents the highest roll out of the 100 inital dice rolls
System.out.println(Arrays.toString(highestRolls)); //Print the array
}
}
}
Example Output after 10 seconds:
...
[73695, 13823, 330563, 5799, 19362, 0]
[73696, 13823, 330563, 5799, 19362, 0]
[73697, 13823, 330563, 5799, 19362, 0]
[73698, 13823, 330563, 5799, 19362, 0]
[73699, 13823, 330563, 5799, 19362, 0]
[73700, 13823, 330563, 5799, 19362, 0]
[73701, 13823, 330563, 5799, 19362, 0]
[73702, 13823, 330563, 5799, 19362, 0]
[73703, 13823, 330563, 5799, 19362, 0]
[73704, 13823, 330563, 5799, 19362, 0]
[73705, 13823, 330563, 5799, 19362, 0]
Any help is appreciated.