Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!