Java random performance 2
Quad-core windows 7
HTML
<script src="https://codehs.com/editor/398065/188165/0/0#docs-operators"></script>
JavaScript
public class MyProgram extends ConsoleProgram
{
public void run(){
String[] starter = {"Pikachu", "Pikachu", "Pikachu", "Pikachu", "Celebi", "Eevee", "Snorlax", "Ditto", "Charizard", "Charmander", "Squirtle", "Bulbasaur"};
for(int x = 1; x < 101; x++){
System.out.println(x);
String[] chosen = new String[5];
int items = 0;
int y = 0;
do{
String random = starter[new Randomizer().nextInt(starter.length)];
if(!inArray(chosen, random)){
System.out.print(random + ", ");
chosen[items] = random;
items++;
y++;
}
} while(y < 5);
// System.out.println();
String[] legendary = {"Mew", "Mew", "Mew", "Mew", "MewTwo", "Articuno", "Lugia", "Regirock", "Kyogre", "Palkia", "Dialga", "Zaptos"};
String random2 = (legendary[new Randomizer().nextInt(legendary.length)]);
System.out.println("Legendary: " + random2);
// System.out.println(random2);
System.out.println();
System.out.println();
}
}
public boolean inArray(String[] arr, String s){
boolean inArray = false;
for(int i = 0; i < arr.length; i++){
if(arr[i] == s){
inArray = true;
}
}
return inArray;
}
}