mercredi 15 mars 2017

Java - Generate random numbers with limit on how many to generate

I need to generate 8 random numbers, 4 being "1"s and the other 4 being "2"s and then assign them to an array. I already have the code to generate random numbers: 1 + (int)(Math.random() * ((2 - 1) + 1))

What I need to do is to have 4 "1"s and 4 "2"s in a random order.




Aucun commentaire:

Enregistrer un commentaire