lundi 4 octobre 2021

Java Fill an array with distinct random numbers [closed]

I want to fill an array with a distinct number between 1 to 50.

this is how i wrote it in javascript:

function choose(){
    var ball_no, previous, unique;
    for (ball_no = 0; ball_no < 6; ball_no++){
        unique = false;
        while(unique == false){
            jball[ball_no] = Math.round(Math.random() * 49) + 1;
            unique = true;
            for(previous = 0; previous < ball_no; previous++){
                if(jball[previous] == jball[ball_no]) unique = false;
            }
        }
    }
}

How can I write this with java?




Aucun commentaire:

Enregistrer un commentaire