vendredi 14 juillet 2017

Generating random distinct pair with no diagonals java

i want to generate two random pair of integer with no duplicate in an arry of length 8 and i dont want any pair in the same diagonal

public static int[] randomizer(int[] v){
    int [] a= new int[8];
    for (int i = 0; i < a.length; i++) {
        a[i] = (int)(Math.random()*9);

        for (int j = 0; j < i; j++) {
            if (a[i] == a[j]) {
                i--;
                break;
            }

        }
    }
    a[0] = v[0] ;
    return a;
}

this is what i have done so far




Aucun commentaire:

Enregistrer un commentaire