Skip to content
AgileLogics

Random Binary Generator

Generates a random string of 0s and 1s of a chosen length.

How it works

Choose a length, then click Generate.

What is a random binary generator?

A random binary generator produces a string of bits, each a 0 or a 1 chosen at random. This one builds strings from 1 to 1024 bits long, with every bit an independent 50/50 draw from your browser's cryptographically secure generator. An 8-bit result is one of 256 equally likely patterns, from 00000000 to 11111111.

How to generate bits

  1. Move the Length (bits) slider to the number of bits you need. The default is 8; the maximum is 1024.
  2. Click Generate.
  3. Copy the string. It contains only the characters 0 and 1, with no spaces, prefixes like 0b, or line breaks.

Example: a 32-bit pattern

At 32 bits, one run produced:

01111100111101000111101011011010

Read in groups of four, that's 0111 1100 1111 0100 0111 1010 1101 1010, which maps digit by digit to hex 7cf47ada. Pasting the string into the binary to hex converter gives the same 7cf47ada, and the binary to decimal converter gives 2,096,397,018. The first bit is 0, which is why the decimal value is below 2³¹ (2,147,483,648): a 32-bit signed integer would read this as positive.

How random is "random" for bits?

Short strings look less random than people expect. In 8 bits, exactly four 1s and four 0s happens only 70 times out of 256, about 27% of the time; runs such as 11110000 or 00000000 are just as likely as 10110010. Over longer strings the balance tightens. At 1024 bits you'd expect 512 ones, with a standard deviation of 16, so about 95% of strings have between 480 and 544 ones.

That balance is exactly what the first statistical check in NIST SP 800-22, the frequency (monobit) test, looks at. You can count the 1s in a 1024-bit output yourself to see it. This tool isn't a substitute for running a proper test suite on a generator you built, but the strings are useful as known-random input when you're writing such a test.

Under the hood each bit is a call to the shared randomInt(0, 1) helper, which draws a 32-bit value from crypto.getRandomValues and reduces it with rejection sampling. It's wasteful (32 random bits spent per output bit) but it means there's no way for one bit to influence another.

Lengths and how many patterns they cover

Length Possible patterns Typical use
4 bits 16 One hex digit, a nibble
8 bits 256 A byte, a set of 8 flags
16 bits 65,536 Port numbers, 16-bit registers
32 bits about 4.3 billion IPv4-sized values, 32-bit masks
64 bits about 1.8 × 10¹⁹ 64-bit integers, bitboards
1024 bits 2¹⁰²⁴ Long streams for tests

Where random bit strings are useful

  • Testing bitmask code. Generate 8, 16 or 32 bits and use them as a permission mask or feature-flag set to exercise every branch of the code that reads them.
  • Parser and validator input. A field that should accept only binary digits (or exactly 8 of them) needs test values; a random string with leading zeros quickly catches parsers that silently convert to a number and drop them.
  • Teaching place value. Students convert a random byte to decimal by adding the place values of the 1s (128, 64, 32 and so on down to 1), then check with a converter.
  • Puzzles and games. Nonograms, binary-number puzzles and "guess the pattern" exercises all start from a random grid of bits.

Things to watch for

  • Text decoders need spaces. The output has no separators, so a "binary to text" decoder that expects 8-bit groups, such as the reverse mode of text to binary, rejects anything longer than 8 bits until you split it into bytes. Random bytes also rarely decode to readable text.
  • Converters cap at 53 bits. Beyond that, the site's base converters return "That number is too large to convert precisely." Split long strings into 32-bit chunks, or use the random hex generator if hex is what you wanted in the first place.
  • No grouping, no prefix. If your language needs a literal like 0b0111..., add the prefix yourself.

Everything happens on the page itself; the bits aren't sent anywhere or stored.

Last updated

Frequently asked questions

Is every bit equally likely to be 0 or 1?
Yes. Each bit is a separate draw from crypto.getRandomValues, reduced to 0 or 1 with rejection sampling, so the two values are equally likely and no bit depends on another.
Why are there leading zeros?
Because the output is a string of bits, not a number. A random 8-bit pattern starts with 0 half the time, and dropping it would change the length. If you paste the result into a spreadsheet, format the column as text first or the zeros will disappear.
Can I get the bits in groups of 8?
Not directly. The output is one unbroken string. If you need bytes separated by spaces, the random byte generator gives 0 to 255 values you can convert, or insert a space every 8 characters in your editor.
How do I convert the result to hex or decimal?
Paste it into the binary to hex or binary to decimal converter. Those converters handle up to 53 bits, the largest integer JavaScript can represent exactly, so for longer strings convert in chunks or use a language with big integers.