lundi 25 décembre 2017

How to generate 5 different numbers in javasripct

I have a click function so that when i click on a button it should put 5 different numbers into a table. The problem here is that the five aren't always different.

$("button").click(function () {
$("table:eq(2)").show();
y = 0;
while (y < 5) {
    x = Math.floor((Math.random() * 50) + 1);
    klo = 0;
    kolonija[y] = x;
    if (tru==1)
    {

        while(klo<5){

            while(kolonija[y]==rezerva[klo])
            {
                x = Math.floor((Math.random() * 50) + 1);
                kolonija[y] = x;
            }


            klo++
        }
        rezerva[klo] = x;
    }
    else if (tru == 0)
    {
        rezerva[y] = x;
        tru == 1;
    }


    $("table:eq(2) td:eq(" + y + ")").text(x);


    y++;
}
});




Aucun commentaire:

Enregistrer un commentaire