Skip to content
AgileLogics

Random Byte Generator

Generates a chosen number of random bytes (0-255) as space-separated decimal values, using a cryptographically secure random source.

How it works

Choose how many bytes, then click Generate.

What does a random byte generator do?

It produces random bytes, the 8-bit values from 0 to 255 that every file and network message is built from. This tool asks your browser's cryptographic random source for 1 to 256 bytes and prints them as decimal numbers separated by spaces. Each value is used as delivered, so all 256 values are exactly equally likely.

Generating bytes

  1. Set Bytes to the number you need (1 to 256; the default is 16).
  2. Click Generate.
  3. Copy the line of numbers.

Sixteen bytes is 128 bits, the size of an AES-128 key or a UUID. Thirty-two bytes is 256 bits.

Example: 16 bytes, read three ways

A 16-byte run returned:

112 3 182 81 225 232 238 177 2 75 42 10 109 183 148 128

Here are a few of those bytes in hex and binary, and what each would mean if a program tried to read the sequence as UTF-8 text (RFC 3629):

Decimal Hex Binary As UTF-8
112 70 01110000 ASCII letter p
3 03 00000011 Control character (end of text)
182 B6 10110110 Continuation byte, invalid on its own
225 E1 11100001 Starts a 3-byte character
10 0A 00001010 Line feed
128 80 10000000 Continuation byte

That mix is the point. Random bytes contain control characters, line breaks, high-bit values and broken multi-byte sequences, exactly the things that trip up code which assumes its input is clean text.

Turning the output into code

Swap the spaces for commas and wrap the result in your language's array syntax:

const bytes = new Uint8Array([112, 3, 182, 81, 225, 232, 238, 177]);
data = bytes([112, 3, 182, 81, 225, 232, 238, 177])
unsigned char data[] = {112, 3, 182, 81, 225, 232, 238, 177};

Decimal is the one format every language accepts in an array literal without a prefix, which is why this tool uses it rather than hex.

Fuzzing text decoders with random bytes

A quick way to test a parser, decoder or file importer is to feed it random bytes and make sure it fails cleanly instead of crashing or producing garbage silently. Some numbers worth knowing:

  • Half of all random bytes are 128 or above, outside ASCII. The chance that 16 random bytes are all ASCII is 1 in 65,536.
  • RFC 3629 states that the byte values C0, C1 and F5 to FF never appear in valid UTF-8. That's 13 of the 256 values, and the chance that at least one of them turns up in 16 random bytes is about 57%.
  • Even without those values, continuation bytes (128 to 191) appearing without a lead byte break most sequences. When we decoded 100,000 random 16-byte blocks with a strict UTF-8 decoder, more than 99.9% were rejected.

A good decoder should report an error for these. The decimal to ASCII converter shows another common behaviour: it reads each number as a character code, so 182 becomes ¶ (the Latin-1 reading) instead of an error.

Where the bytes come from

The tool calls crypto.getRandomValues on a Uint8Array of the length you chose and joins the values with spaces. MDN describes this source as a pseudo-random generator seeded with enough entropy to be suitable for cryptographic purposes; the designs behind such generators are covered by NIST SP 800-90A. Unlike the site's number-range generators, there's no rejection sampling here because none is needed: the range you want (0 to 255) is exactly what one byte holds.

The bytes are generated on your device and aren't uploaded or logged.

Good uses

Task Suggested length
Test vector for a checksum or CRC function 8 to 64 bytes
Fuzz input for a binary or text parser 64 to 256 bytes
Fixture data for a byte-array field in tests whatever the field holds
Salt or nonce placeholder in sample code 12 to 16 bytes
Teaching hex, binary and character encodings 4 to 8 bytes

To read individual values in other bases, use the decimal to hex and decimal to binary converters, one number at a time. If you'd rather have the bytes as a single compact string, the random hex generator is the better fit.

Last updated

Frequently asked questions

What format are the bytes in?
Decimal numbers from 0 to 255, separated by single spaces, on one line, for example 112 3 182 81. There are no commas, brackets or 0x prefixes, so replace the spaces with commas to make an array literal.
Is each byte value equally likely?
Yes, exactly. The tool fills a Uint8Array with crypto.getRandomValues and prints the values as they are, so each of the 256 values has a 1 in 256 chance. No scaling or remainder step is involved that could introduce bias.
Can I use these bytes as an encryption key?
They come from a cryptographically secure source, so they're random enough, but a key copied out of a web page passes through your clipboard and screen. For real keys, generate them inside the program that uses them, for example with the Web Crypto generateKey method, which MDN recommends for key generation.
How do I get the bytes in hex instead?
Use the random hex generator, which produces the same kind of random bytes written as two hex digits each. To convert a single value from this tool, the decimal to hex converter turns 182 into b6.