Skip to content

Instantly share code, notes, and snippets.

@Bharathbrothers
Created November 13, 2018 02:42
Show Gist options
  • Save Bharathbrothers/965fd4244e3137669379c1392ddf1f5a to your computer and use it in GitHub Desktop.
Save Bharathbrothers/965fd4244e3137669379c1392ddf1f5a to your computer and use it in GitHub Desktop.
How to generate unique random numbers in Java?
ArrayList<Integer> array = new ArrayList<>(4);
ArrayList<Integer> input = new ArrayList<>(4);
for(int i=0;i<10;i++){
array.add(i);
}
Collections.shuffle(array);
for(int j=0;j<4;j++){
input.add(array.get(j));
}
// This generates unique numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment