Random hex generator for hexadecimal values
Hexadecimal (base 16) uses the digits 0–9 and the letters a–f. One hex digit represents four bits, so two digits make a byte. This random hex generator produces values with an exact number of digits, each chosen uniformly from the 16 possibilities using a secure random source.
Examples
8 digits: 3fa91c07
16 digits, upper: 9B2E04D7C18F5A63
8 digits, 0x prefix: 0x7d0e41b9
6 digits: c4e2a8 (usable as a color: #c4e2a8)
How long should a hex value be?
| Hex digits | Bits | Looks like |
|---|---|---|
| 6 | 24 | A CSS color such as #1e90ff |
| 7–12 | 28–48 | A short Git commit hash, a MAC address without separators |
| 32 | 128 | An MD5 digest or a UUID without hyphens |
| 40 | 160 | A full SHA-1 / Git commit hash |
| 64 | 256 | A SHA-256 digest or a 256-bit key |
Random hex strings of these lengths are ideal as placeholder hashes in documentation, fixtures and UI mockups. Keep in mind they are random, not real digests: if you need the actual hash of some text, use the SHA-256 hash generator.
Uses
- Fake commit hashes, transaction IDs or checksums for test data and screenshots.
- Random color codes (use 6 digits and add a
#); for a visual palette try the random color generator. - Memory addresses and register values in debugging exercises.
- Tokens and nonces where hex is the expected format.
Options
- Length – 1 to 1024 hex digits per value.
- Case – lowercase is the convention for hashes and most APIs; uppercase is common in hardware documentation and Windows tools.
- 0x prefix – the hex literal syntax in C, JavaScript, Python, Java and many other languages.
- Unique and separator – avoid duplicates and choose line, comma or space separation.
Reading hex quickly
Each hex digit maps to exactly four bits: 0 = 0000, 8 = 1000, a = 1010 and f = 1111. That is why hex is the preferred way to show binary data compactly: a byte is always two digits, and you can read the bits of any digit without calculation once you know the sixteen patterns.
To turn a hex value into a readable number, use hex to decimal. All values are created in your browser and are never sent to a server.
How many digits avoid duplicates?
Short random values collide sooner than most people expect, because of the birthday problem: the chance of a repeat depends on the number of pairs, not the number of values. As a rough guide, you reach a 50% chance of at least one duplicate after about:
| Hex digits | Possible values | 50% chance of a repeat after |
|---|---|---|
| 4 | 65,536 | about 300 values |
| 8 | about 4.3 billion | about 77,000 values |
| 16 | about 1.8 × 1019 | about 5 billion values |
| 32 | 2128 | far beyond any real workload |
Within one batch, the Unique values option removes repeats for you. Values generated on different days or by different people are not compared with each other, so choose 16 digits or more for IDs that must stay distinct across a whole system.