mardi 8 septembre 2020

Generating a random number with different digits in java

I'm trying to generate a random number with 4 different digits.

The catch is that it needs to be a one-liner, the solution doesn't need to be pretty.

I already tried using Collections.shuffle(Mylist) but I couldn't make it in one line.

My code so far:

List<Integer> digits = IntStream.range(0,10).boxed().collect(Collectors.toList());
Collections.shuffle(digits);
System.out.println(digits.subList(0,4));



Aucun commentaire:

Enregistrer un commentaire