jeudi 9 mai 2019

How to get random number (1-5) without repeating any

I need to shuffle numbers between 1 and 5 without repeating any. I have figured out how to randomly generate them, but how do I make it so no numbers repeat without changing my code drastically?

  //Set up randomization when initializing board
  Random rn = new Random();

  int color1 = rn.nextInt(5) + 1;
  int color2 = rn.nextInt(5) + 1;
  int color3 = rn.nextInt(5) + 1;
  int color4 = rn.nextInt(5) + 1;
  int color5 = rn.nextInt(5) + 1;




Aucun commentaire:

Enregistrer un commentaire