Bonjour,
Je voudrais savoir comment faire pour générer un code de 6 caractères alphanumérique.
merci pour vos réponses.
Bonne journée !
Bonjour,
Je voudrais savoir comment faire pour générer un code de 6 caractères alphanumérique.
merci pour vos réponses.
Bonne journée !
random du code ascii ?
Ma page Developpez - Mon Blog Developpez
Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
Votre post est résolu ? Alors n'oubliez pas le Tag![]()
Venez sur le Chat de Développez !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>...</title> <script type="text/javascript"> var tab=new Array(); var tab2=new Array(); function random(disp){ for(i=48;i<58;i++){ tab.push(i) }; for(i=65;i<91;i++){ tab.push(i) }; for(i=97;i<123;i++){ tab.push(i) }; for(i=0;i<6;i++){ var h=Math.floor(Math.random()*tab.length); tab2[i]=String.fromCharCode(tab[h]); tab.splice(h,1) }; disp.firstChild.data=tab2.join(' '); } </script> </head> <body> <div id="mess" style="margin:100px;text-align:center"> ... </div> <p style="text-align:center"> <input type="button" value="random" onclick="random(document.getElementById('mess'))" /> </p> </body> </html>
juste pour le fun JT ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 <script type="text/javascript"> var tab=new Array(); var tab2=new Array(); function random(disp){ var licenceCode='' for(i=48;i<58;i++){ tab.push(i) }; for(i=65;i<91;i++){ tab.push(i) }; for(i=97;i<123;i++){ tab.push(i) }; for (j=0;j<5;j++){ tab2[j]=new Array() for(i=0;i<6;i++){ var h=Math.floor(Math.random()*tab.length); tab2[j][i]=String.fromCharCode(tab[h]); tab.splice(h,1) }; licenceCode+=tab2[j].join('')+' - ' } disp.firstChild.data=licenceCode.substr(0,licenceCode.length-3) } </script>
Ma page Developpez - Mon Blog Developpez
Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
Votre post est résolu ? Alors n'oubliez pas le Tag![]()
Venez sur le Chat de Développez !
Ok, merci pour votre aide, je l'ai fait comme ça, avec votre aide:
Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 function generate() { var tab=new Array(); var tab2=new Array(); for(i=48;i<=57;i++){tab.push(i);} for(i=65;i<=90;i++){tab.push(i);} for(i=97;i<=122;i++){tab.push(i);} tab2[0]=String.fromCharCode(tab[Math.round((Math.random()*tab.length))]); for(i=1;i<=6;i++) { var recur=(tab2[i-1].charCodeAt(0))%(tab.length); var indice=Math.round(Math.random()*tab.length); tab2[i]=String.fromCharCode(tab[(recur+indice)%tab.length] ); } var code=tab2.join(''); document.write(code); }
Partager