Random hex generator — hexadecimal strings by the byte

Say how many random bytes you want and the tool writes each value as hexadecimal, two characters per byte, in lower or upper case and with an optional 0x prefix.

Live demo · real result from this tool
Each byte is two hex characters.
Case

Press Generate to create a result.

Processed on your device — nothing is uploaded.

How to use the random hex generator

  1. Enter the number of Bytes, from 1 to 1,024 (16 by default). Each byte is two hex characters.
  2. Choose the Case: lowercase or UPPERCASE.
  3. Tick Add 0x prefix if the value is going into code as a number.
  4. Set How many values you need (up to 1,000) and press Generate.
  5. Copy the list. The stats show the Randomness in bits and the number of Hex characters per value.

What it does and when to use it

Hexadecimal is the usual way to write raw bytes as text. This tool is for any job where you need random bytes in that form: a CSRF token, a password salt, a request or trace ID, a nonce for a test, sample data for a hex viewer, or random 32-bit constants such as 0x9F3A21C0 for a unit test.

Because you set the size in bytes, the strength is easy to read: bytes × 8 = bits. If the bytes are meant to be a cipher key, the encryption key generator offers named AES, ChaCha20 and HMAC sizes plus Base64 output. For random text with letters beyond A–F, use the random string generator. For a random colour as a hex code with RGB and HSL values, try the random color generator.

How it works

For each value the tool asks crypto.getRandomValues for the chosen number of bytes. Each byte (0 to 255) is written as two hex digits, with a leading zero when needed, so 0 becomes 00 and 255 becomes ff. The hex is then upper-cased if you asked, and 0x is added at the front if ticked.

Nothing is hashed or stretched, so all of the bits are random. That is why Randomness is simply the byte count × 8.

Worked examples

  • The default 16 bytes. Each value is 32 hex characters, such as efbad07eb575bbcf588655f721a2ee90, and the stats read Randomness: 128 bits.
  • A 32-bit constant for code. Bytes 4, UPPERCASE, 0x prefix on. Values look like 0x5BD3980F, and the stats show Hex characters: 8. The prefix is not counted.
  • Over the limit. Asking for 2,000 bytes is capped at 1,024, so the result has Hex characters: 2,048 and 8,192 bits.

Limits and tips

  • Values in a batch are independent; the tool does not check them for duplicates. With 4-byte values, the chance of a repeat reaches about one half after roughly 77,000 draws.
  • Hex is twice the size of the raw bytes. If space matters, Base64 is shorter for the same randomness.
  • Treat any value you use as a secret like a password, and never reuse one across systems.

Frequently asked questions

Why does the tool ask for bytes instead of characters?
Most specifications state sizes in bytes or bits, such as a 16-byte token or a 32-byte salt. Each byte is always exactly two hex characters, so 16 bytes gives a 32-character string and 128 bits of randomness.
Does upper or lower case change the value?
No. 9F3A and 9f3a are the same number. Lowercase is common in Linux tools, hashes and web APIs; uppercase is common in Windows tools, datasheets and some hardware documents. Pick whichever the receiving system shows.
When should I add the 0x prefix?
When the value goes into source code as a number literal, for example in C, C++, Java, JavaScript or Python. Leave it off for tokens, salts and anything stored as text, where the extra two characters would only get in the way.
Is this good enough for security tokens?
Yes, if the length is right. The bytes come from crypto.getRandomValues, the browser's cryptographically secure generator. 16 bytes (128 bits) is a common minimum for session IDs and reset tokens; 32 bytes gives a wide margin.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close