Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
Generating PINS - guarding, limiting and fastest way

My task for today is to generate a PIN. A four digit pin. It has to be random. Are there limitations to doing it and doing it the way I plan? I understand humans can never create something TRULY random but hey who we have to try.

I am currently generating it in client (JS), then passing to the Model (C#) and this is injected to the DB (Oracle). The only safeguards I can think of so far is either generate from 0001 > onwards to anything less than 10000 so 9999 will be the highest number. Anything that is returned that is between these two numbers as long as it has not been used before in my logic is random - we also know we have to check the db to see if the PIN already exists IF NOT then generate it.

I guess I can:

onGen() { 
    //generate pin
    var pin = characters.charAt(Math.floor(Math.random() * charactersLength));
    //check db if pin exists
    const exists = checkDB('select pin from pins where pin =' + pin + ';')
    //if pin exist generate again
    if(exists) pin = characters.charAt(Math.floor(Math.random() * charactersLength));
    //also should I put my login of 0001 > and < 10000 in the SELECT or js?
    if pin > 0000 return pin
    //or this
    checkDB('select pin from pins where pin =' + pin + 'AND pin > 0001 and pin < 10000;')
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda