It works roughly as below. I will try to explain in the simplest way I know:
Total letters: 26 (taking into account only the capital letters of the common alphabet)
Total numbers: 10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
The bill is basically: 26 * 26 * 26 * 10 * 10 * 10
(AAA-000)
The result is:
var totalLetras = 26;
var totalNumeros = 10;
// baseado na string 'AAA-000'
var totalCombinacoes = totalLetras * totalLetras * totalLetras * totalNumeros * totalNumeros * totalNumeros;
console.log(totalCombinacoes);
A possible formula would be:
function gerarCombinacao() {
var combinacao = retornarLetra().toString();
combinacao = combinacao.concat(retornarLetra());
combinacao = combinacao.concat(retornarLetra());
combinacao = combinacao.concat("-");
combinacao = combinacao.concat(retornarNumero());
combinacao = combinacao.concat(retornarNumero());
combinacao = combinacao.concat(retornarNumero());
return combinacao;
}
console.log(gerarCombinacao());
//retorna as letras do alfabeto a partir do charCode: 65 até 90 (A-Z)
function retornarLetra() {
return String.fromCharCode(64 + Math.ceil(Math.random() * 26)).toString();
}
// retorna os números de 0 a 9
function retornarNumero() {
return Math.round((Math.random() * 9)).toString();
}
In php:
<?php
function gerarCombinacao() {
// retorna as letras de A-Z
$combinacao = chr(rand(65,90));
$combinacao .= chr(rand(65,90));
$combinacao .= chr(rand(65,90));
// adiciona o "-"
$combinacao .= "-";
// retorna os números de 0 a 9;
$combinacao .= rand(0,9);
$combinacao .= rand(0,9);
$combinacao .= rand(0,9);
return $combinacao;
}
echo gerarCombinacao();
You can see this code functioning here.
@Andersoncarloswoss had an answer from you or Jefferson that talked about using Python’s libiter tools, this is a good start
– Guilherme Nascimento
Dear Tiago is javascript or PHP? Because the suggestions I have in mind are very different.
– Guilherme Nascimento
Letters will always be uppercase or can differentiate between uppercase and lowercase?
– Woss
26 3 x 10 3 possible combinations, simply because the positions are immutable. What is the purpose of calculating this?
– Jefferson Quesado