You need a stack of codes and you need them to be genuinely random: voucher codes for a promotion, PINs for a classroom exercise, placeholder one-time codes while you build the real login flow. The tempting shortcuts are all bad ones. Counting up from 1000, reusing your own phone number pattern, or letting a spreadsheet fill a series all produce codes an attacker or a curious student can guess in order.
A code is only worth anything if nobody can predict the next one from the last one. This guide explains how random codes are made properly, and how to generate them with the free Random PIN and OTP Code Generator on Ovatly, which runs in your browser and stores nothing.
Contents
- Quick answer
- What makes a code random enough to trust
- PINs, one-time codes and vouchers: picking a length
- Why leading zeros matter
- How to generate codes, step by step
- Worked example: one real run at 6 digits
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Open the Random PIN and OTP Code Generator, choose how many digits each code should have (4 for a classic PIN, 6 for an OTP-style code, more for vouchers), set how many codes you need, up to 500, and press Generate codes. Copy the list or download it as a text file with one code per line. The codes come from your browser's cryptographic random source, leading zeros are preserved, and nothing is stored once you leave the page. One honest warning up front: these are standalone random codes, not time-based OTPs, and the limitations section below explains the difference.
What makes a code random enough to trust
Every digit in these codes comes from the operating system's cryptographic random generator, through the browser's crypto.getRandomValues call, the same source your browser uses for TLS, the encryption behind secure connections. That source is designed to be unpredictable: knowing every code generated so far tells you nothing about the next one.
The generator also uses rejection sampling when it turns random values into digits. That is a technical detail with a practical payoff: every digit from 0 to 9 is uniformly distributed, with no modulo bias making some digits slightly more likely than others. A biased generator would hand an attacker a shorter list of likely codes to try first. An unbiased one gives every code of the chosen length an equal chance, which is the whole point.
PINs, one-time codes and vouchers: picking a length
The digit count sets the size of the space an attacker would have to search. Four digits give 10,000 possible codes, which suits a classic PIN: short enough to type from memory, and normally paired with a system that locks after a few wrong tries. Six digits give a million possibilities, the familiar shape of a one-time code. Vouchers and other codes that might be tried repeatedly, with no lockout protecting them, deserve more digits, because length is the only defence they have.
Match the length to how the code will be used, not to habit. A classroom code that expires at the end of the lesson can be short. A voucher code printed and handed out for months should be long.
Why leading zeros matter
A code is a string of digits, not a number. The code 0042 is four digits long, and the two zeros at the front are as much a part of it as the 4 and the 2. Tools that treat codes as numbers quietly drop those zeros, and the person holding 0042 gets told their code is wrong when they type all four digits.
This generator keeps leading zeros in both the on-screen list and the downloaded file, so the code you hand out is the code that works. The worked example below shows a real case.
How to generate codes, step by step
- Open the Random PIN and OTP Code Generator and choose the digits per code: 4 for a classic PIN, 6 for an OTP-style code, or more for vouchers.
- Set how many codes you need, up to 500 in a single run.
- Press Generate codes and look over the list.
- Copy the list, or download it as a text file with one code per line, ready to paste into your own system or print.
Worked example: one real run at 6 digits
One real run of the generator at 6 digits produced these five codes:
492715
004730
835137
959162
298439
Look at the second one. 004730 starts with two zeros, and those zeros are real digits of the code, preserved in both the copy and the download. If this code were stored as a number somewhere along the way, it would collapse to 4730 and stop matching what the holder types.
Your run will produce different codes. That is not a flaw in the example; it is the definition of the tool working. A generator whose output you could reproduce from an example would be a generator whose output anyone could reproduce.
Limitations and honest tradeoffs
The most important limit: these are standalone random codes, not time-based OTPs. A real OTP system derives each code from a shared secret and the clock, the method called TOTP, so the code changes on its own and proves the holder has the secret. This tool does not do that, and the codes it makes should never be presented as a TOTP replacement. Used as pre-generated single-use codes, like backup codes or voucher codes, they can work, provided you store them hashed and expire them properly on your side.
Duplicates are possible by chance in large batches. Only 10,000 four-digit codes exist, so in a batch of 500, repeats are likely; that is the birthday effect, not a malfunction. If your use needs uniqueness, deduplicate the list after generating.
Nothing is stored. The list disappears when you leave the page unless you download it, and there is a cap of 500 codes per run to keep the page responsive. Run it again if you need more.
Common mistakes
- Treating the codes as numbers downstream. A spreadsheet or database column set to numeric will strip leading zeros and corrupt codes like 004730. Store codes as text everywhere.
- Using these codes as a TOTP substitute. They are pre-generated values, not clock-derived proofs. A login system needs the real OTP flow; these codes suit backup and voucher roles.
- Storing the list in plain text. If the codes grant anything of value, store them hashed on your side and expire them after use, the same discipline you would apply to passwords.
- Assuming a batch is unique. Check for duplicates before issuing a large batch, especially at 4 digits.
- Picking a length by habit. Four digits behind no lockout is a small search space. Let the risk decide the length.
FAQs
How many codes can I generate at once? Up to 500 per run, which keeps the page responsive. If you need more, run it again and combine the lists, then deduplicate if uniqueness matters.
Why did the same code appear twice in my batch? That is the birthday effect, not a bug. Random draws collide, especially in small spaces: with 500 four-digit codes, repeats are likely because only 10,000 four-digit codes exist. Generate the batch and remove duplicates if you need every code to be unique.
Can I use these codes as the one-time passwords for my app? As pre-generated single-use codes, such as backup codes or voucher codes, they can work if you store them hashed and expire them properly. They are not a substitute for TOTP or SMS and app OTP flows, because they are not derived from a shared secret and the clock.
Are the codes saved anywhere? No. Nothing is stored, and the list disappears when you leave the page unless you download it as a text file first.
Why does a code like 004730 keep its leading zeros? Because the zeros are real digits of the code. The generator builds each code as a fixed-length string of digits, so a four-digit code stays four digits and a six-digit code stays six, in both the copy and the download.
Conclusion
A random code earns its keep in two ways: nobody can predict it, and it survives the journey from generator to user without losing digits. The Random PIN and OTP Code Generator covers both, drawing from a cryptographic random source with unbiased digits and preserving leading zeros in the copy and the download. When you need the other side of the password question, whether a long string of characters or a phrase you can remember serves you better, read Passphrase vs Random Password: Which Is Better. For more guides in this series, see our Security and Privacy guides, which pair each technique with the free tool that performs it.
References
- MDN Web Docs, on
crypto.getRandomValuesand cryptographically secure random values in the browser: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues - RFC 6238, on TOTP, the time-based one-time password algorithm real OTP systems use: https://www.rfc-editor.org/rfc/rfc6238