mercredi 21 juillet 2021

What is the time complexity of random.nextInt() in Java?

I'm wondering what the time complexity of random.nextInt() is in Java.

I will attach a snippet of code down below:

Random rand = new Random();
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
int[] randomNums = new int[list.size()];
int i = 0;
while(i < randomNums.length) {
    int index = rand.nextInt(list.size());
    randomNums[i++] = list.get(index);
    list.remove(index);
}
return randomNums;



Aucun commentaire:

Enregistrer un commentaire