Methods, Arrays, and Loops - Oh My! Lottery question in Java.

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 709 Views - Last Post: 03 April 2013 - 06:38 PM Rate Topic: -----

#16 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Methods, Arrays, and Loops - Oh My! Lottery question in Java.

Posted 03 April 2013 - 06:38 PM

To uniquely extract stuff, use an ArrayList and randombly remove from it

ArrayList<Character> al = new ArrayList<Character>();
for(char c = 'A'; c <= 'Z'; ++c)
   all.add(c);

Random ran = new Random();

// you can repeat this statement 26 times
// each time it will return a unique letter
char unique = al.remove(ran.nextInt(al.size()));


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2