if (number1 == number2)and it didn't work.Plus that only helps if there are 2 players.
Please help! Thanks!
Posted 18 January 2012  07:35 PM
if (number1 == number2)and it didn't work.Plus that only helps if there are 2 players.
Posted 18 January 2012  07:41 PM
This post has been edited by Mylo: 18 January 2012  07:42 PM
Posted 18 January 2012  07:43 PM
Mylo, on 18 January 2012  07:41 PM, said:
Posted 18 January 2012  07:51 PM
public static void main(String[] args) { ArrayList<Integer> numbers = new ArrayList<Integer>(); numbers.add(1); numbers.add(2); numbers.add(3); numbers.add(4); numbers.add(5); numbers.add(6); int[] playerscores = new int[6]; for (int i = 0; i < playerscores.length; ++i) { int rnd = (int) (Math.random() * numbers.size()); playerscores[i] = numbers.get(rnd); numbers.remove(rnd); } for (int x : playerscores) { System.out.println(x); } }
This post has been edited by Mylo: 18 January 2012  07:52 PM
Posted 18 January 2012  07:58 PM
Mylo, on 18 January 2012  07:51 PM, said:
public static void main(String[] args) { ArrayList<Integer> numbers = new ArrayList<Integer>(); numbers.add(1); numbers.add(2); numbers.add(3); numbers.add(4); numbers.add(5); numbers.add(6); int[] playerscores = new int[6]; for (int i = 0; i < playerscores.length; ++i) { int rnd = (int) (Math.random() * numbers.size()); playerscores[i] = numbers.get(rnd); numbers.remove(rnd); } for (int x : playerscores) { System.out.println(x); } }
Posted 18 January 2012  08:03 PM
private ArrayList<Integer> numbers; private Random rnd = new Random(); //Add the numbers 16 to the numbers arraylist public void fillArrayList() { numbers = new ArrayList<Integer>(); for (int i=1; i<=6; i++) numbers.add(i); } public int roll() { if (numbers.size() > 0) return numbers.remove(rnd.nextInt(numbers.size())); return 1; //The array is empty! }
This post has been edited by CasiOo: 18 January 2012  08:03 PM
Posted 18 January 2012  08:09 PM
CasiOo, on 18 January 2012  08:03 PM, said:
private ArrayList<Integer> numbers; private Random rnd = new Random(); //Add the numbers 16 to the numbers arraylist public void fillArrayList() { numbers = new ArrayList<Integer>(); for (int i=1; i<=6; i++) numbers.add(i); } public int roll() { if (numbers.size() > 0) return numbers.remove(rnd.nextInt(numbers.size())); return 1; //The array is empty! }
Posted 18 January 2012  08:13 PM
Posted 18 January 2012  08:15 PM
JameyWright, on 18 January 2012  08:09 PM, said:
CasiOo, on 18 January 2012  08:03 PM, said:
private ArrayList<Integer> numbers; private Random rnd = new Random(); //Add the numbers 16 to the numbers arraylist public void fillArrayList() { numbers = new ArrayList<Integer>(); for (int i=1; i<=6; i++) numbers.add(i); } public int roll() { if (numbers.size() > 0) return numbers.remove(rnd.nextInt(numbers.size())); return 1; //The array is empty! }
Query failed: unknown local index 'forums_search_posts_main' in search request.
