Skip to content

Instantly share code, notes, and snippets.

@AndrewHanes
Created June 1, 2014 17:50
Show Gist options
  • Save AndrewHanes/f0bffbcdece48d6f5100 to your computer and use it in GitHub Desktop.
Save AndrewHanes/f0bffbcdece48d6f5100 to your computer and use it in GitHub Desktop.
Random number picker
import java.util.*;
public class rand {
public static void main(String[] args) {
ArrayList<Integer> al = new ArrayList<Integer>();
for(int i = 0; i < 10; ++i) {
al.add(i);
}
Random r = new Random();
ArrayList<Integer> result = new ArrayList<Integer>();
for(int i = 0; i < 5; ++i) {
int index = r.nextInt(al.size());
result.add(al.remove(index));
}
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment