Random.nextInt(int n) method is generating numbers randomly with equal number of chances for each number from the given range. But i need to get output numbers with equal number of times from given range 0-5 Ex: n=5;
For (int i=0; i<10;i++) {
Syso(random.nextInt(n));
}
Giving output Each number randomly between 0-n but i need output such like each number should come twice as loop is happening for 10 times even the generation is random like 2,4,1,3,5,1,5,4,2,3
Is there any java api to achieve this or any logic would help me.
Aucun commentaire:
Enregistrer un commentaire