-
-
Save hungbang/5bdab2dc182711346ed305f2a0403936 to your computer and use it in GitHub Desktop.
How to generate unique random numbers in Java?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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