You do not need to use repeat structures to generate alphanumeric values. Just use a base in the function toString
, for example:
let first = Math.random() // Gera um valor randômico
.toString(36) // Utiliza a Base36
.substr(-4) // Captura os 4 últimos números
.toUpperCase(); // Converte para maiúscula
let last = Math.floor((Math.random() * (9999 - 1000)) + 1000); // Gera um valor entre 999 e 10000
console.log( `${first}-${last}` )
To Base36 is a numerical system consisting of Arabic numerals from 0 to 9 and Latin letters from A to Z, e.g.: 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z (note that letters may be uppercase or lowercase letters).
for (let num = 0; num <= 35; num++) {
var a = num.toString(); // Decimal
var b = num.toString(2); // Binário
var c = num.toString(8); // Octal
var d = num.toString(16); // Hexadecimal
var e = num.toString(36); // Hexatrigesimal
var n = a + " | " + b + " | " + c + " | " + d + " | " + e + "<br><br>";
document.body.innerHTML += n;
}
The
0000
are fixed or is the place where will generate numbers ?– Isac