samedi 27 août 2022

Random string generator without repeating a combination

I have tried to implement that the combinations are not repeated. in the image you can see how "sd" is repeated twice.

sd

const characters ='qwertyuiopasdfghjklzxcvbnm0987654321';

function generateString(length) {
    let result = ' ';
    const charactersLength = characters.length;
    for ( let i = 0; i < length; i++ ) {
        result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }

    return result;
}



function captura(){
    lon=2;
    can=600;
    for (let i = 0; i < can; i++) {
        document.write(i+1 + ".- " + generateString(lon) + "<br>");
    }

}
captura();

Any help please?




Aucun commentaire:

Enregistrer un commentaire