Free tool · Developer tools
Random hex generator
Set a length in hex digits or bytes and get a fresh random hex string at once, such as 9f3a6c0d21b84e75. Choose the case, a prefix and how the digits are grouped, then copy one string or a whole list.
- Free
- No sign-up
- Runs in your browser
64 bits16 digits can take 2^64 different values.
9f3a6c0d21b84e75
Example only. Your browser draws a new random string when the page loads.
- Example only
- Made on this device
- Digits
- 16
- Bytes
- 8
- Bits
- 64
- Possible values
- 2^64
How to use the Random Hex Generator
- Type a number into Length and choose whether it counts Hex digits or Bytes. One byte is two digits.
- Pick a to f or A to F for the letters, and set a Prefix such as 0x or #.
- Use Group digits and Between groups to split the string into blocks of 2, 4 or 8 digits with a space, colon or dash.
- Choose How many strings you want and press Generate new hex. Tap Copy next to one string or Copy all for the list.
How do I generate a random hex string?
A hex string is a row of digits taken from sixteen symbols: 0 to 9 and a to f. Each digit carries 4 bits, so two digits make one byte, and a string of 16 digits holds 64 bits. This page draws every digit separately with the secure random source of your browser, which is the same call that web applications use for keys and tokens. It does not use the weaker generator behind Math.random. Because 16 divides evenly into the 256 values of a byte, no digit is favored over another.
The default length is 16 digits, which gives strings like 9f3a6c0d21b84e75. If you also pick upper case, the 0x prefix and groups of 4 separated by spaces, the same digits read 0x9F3A 6C0D 21B8 4E75. The table shows that one string in five layouts. Formatting changes only how the digits look, never the digits themselves, so every layout of a string carries the same 64 bits.
| Setting | Result |
|---|---|
| Plain, lower case | 9f3a6c0d21b84e75 |
| Upper case | 9F3A6C0D21B84E75 |
| Prefix 0x, groups of 4 with spaces | 0x9F3A 6C0D 21B8 4E75 |
| Pairs with colons | 9f:3a:6c:0d:21:b8:4e:75 |
| Groups of 8 with a dash | 9f3a6c0d-21b84e75 |
How many hex digits or bytes do I need?
Count by the number of values you need to tell apart. Every extra digit multiplies the number of possible strings by 16. Four digits allow 65,536 strings, eight digits allow 4,294,967,296, and twelve digits allow 281,474,976,710,656. Past twelve digits the page writes the count as a power of two, because the full number runs to dozens of figures.
Sizes are usually given in bits, and the table converts them. A 32 bit value is 8 digits or 4 bytes, a 128 bit value is 32 digits or 16 bytes, and a 256 bit value is 64 digits or 32 bytes. If you type the length in bytes, the result panel shows the digit count next to it, so you can check that 16 bytes became 32 digits. Odd digit counts are allowed, and the panel then shows half a byte, for example 3.5 bytes for 7 digits.
| Bits | Hex digits | Bytes | Possible values |
|---|---|---|---|
| 8 | 2 | 1 | 256 |
| 16 | 4 | 2 | 65,536 |
| 32 | 8 | 4 | 4,294,967,296 |
| 64 | 16 | 8 | 2^64 |
| 128 | 32 | 16 | 2^128 |
| 256 | 64 | 32 | 2^256 |
Can I use a random hex string as a key or a token?
The strings are random enough for test data, sample keys, placeholders, nonces in a demo and ids for a prototype. A hex string is only a way of writing bits. A 32 digit string is as strong as the randomness behind it, and here that is the browser generator, with 128 bits for 32 digits. A guess at a 128 bit value has a 1 in 2^128 chance of being right.
For a secret that protects real accounts, create it inside the system that will use it, so it never passes through a clipboard or a screen share. Treat any value you copied from a web page as seen by that page and by whatever reads your clipboard. Nothing you set here is sent anywhere, but the copy step is still yours to handle with care.
How do I make a hex color or a grouped string?
Set the length to 6 digits, choose the # prefix and pick upper case, and you get a random color code such as #FF5733. Each pair of digits is one color channel from 00 to ff, so the code covers 16,777,216 colors. To read a code back as red, green and blue, use the hex to RGB converter.
Groups make long strings easier to read and to compare by eye. Pairs with colons turn 9f3a6c0d21b84e75 into 9f:3a:6c:0d:21:b8:4e:75, the shape used for fingerprints and identifiers. Groups of 8 with a dash give 9f3a6c0d-21b84e75. If you need to turn hex into another base, the number base converter does that, and the ASCII to hex converter writes text as hex bytes.
Use it with
- HEX to RGB Converter: HEX, RGB, HSL, CMYK conversions.
- Random Number Generator: numbers in a range, no repeats.
- ASCII to Hex Converter: convert ASCII text to hex codes with a byte table, control character names and five output styles. Accents and emoji become UTF-8 bytes.
Questions
How many bits is one hex digit?
One hex digit is 4 bits, so two digits are one byte. A 16 digit string is 64 bits and a 32 digit string is 128 bits.
Is this random hex generator truly random?
Each digit comes from the secure random source built into your browser, with no bias between the sixteen symbols. It is suitable for test data and prototypes. A secret for a real account is better created inside the system that will use it.
Does the generator store or send the strings?
No. The digits are made in the page you have open, and the settings stay in the form. Nothing is uploaded, and reloading the page makes new strings.
What is the longest string I can make?
Up to 2,048 hex digits, which is 1,024 bytes, in one string, and up to 20 strings at a time. Type the length in bytes if your spec counts bytes.
How do I get a random hex color?
Use 6 digits, the # prefix and either case, for example #FF5733. Press Generate new hex for another one, or set How many to 20 for a list.
Why does a string starting with 0 still count?
Every position is drawn on its own, so a leading 0 is as likely as any other digit. The string is text, so the zeros stay in place and the length never shrinks.
The tool's results are computed in your browser by the code on this page; the explanations are checked against the tool's own output.