Random Binary Number Generator

Set a bit length (1–256) and how many you want (1–64), then press the button for that many random strings of 0s and 1s.

Set how many bits long each number should be (1 to 256), how many numbers you want (1 to 64), and press the button. Each result is a string of 0s and 1s of exactly that length, one per line, with every bit chosen independently at random. Leave either field empty and the tool picks a random length up to 255 or a random count up to 63 and writes the value it used back into the box. It is built for programmers who need test bit patterns, students learning binary, and anyone who needs a quick sequence of coin flips.

What the two fields do

  • Length of binary number – the number of bits in each result, from 1 to 256. Common choices are 8 (one byte), 16, 32 and 64. The default is 1, which gives you a single coin flip.
  • How many to generate – how many strings to print, from 1 to 64. The default is 1.

Both fields accept a blank. A blank length becomes a random value from 1 to 255, and a blank count becomes a random value from 1 to 63; the box updates to show what was used so the next press repeats it.

What the output looks like

Each string is printed on its own line in a monospaced block. Because every bit is an independent 50/50 draw, strings can start with 0. An 8-bit request can return 00010110 just as easily as 10110010, so think of the results as fixed-width bit fields rather than as integers with a leading 1. That is usually what you want for masks, flags and test vectors; if you need a number that uses the full width, discard results that start with 0 or set the first bit yourself. There is no built-in conversion to decimal or hex, and duplicates are possible on short lengths (with 3 bits there are only eight patterns, so a batch of 20 will repeat).

BitsDistinct valuesLargest value (decimal)Example result
416151011
825625501101001
1665,53665,5351100101000111101
324,294,967,2964,294,967,29500101110111010010001101011010011
642^64 (about 1.8 × 10^19)18,446,744,073,709,551,61564 characters of 0 and 1
2562^256a 78-digit number256 characters, the length of a SHA-256 hash in binary

Uses

  • Test data for parsers and converters. Generate 64 strings of 32 bits and feed them to a function that converts binary to integers, then check the results against a known-good library.
  • Bitmasks and flag sets. An 8- or 16-bit string is a ready-made random permission mask or feature-flag vector for a unit test.
  • Teaching binary. Hand out ten 8-bit strings and have students convert each to decimal and hexadecimal by hand, then check with the Random Hex Generator's output for comparison.
  • Coin flips and yes/no sequences. A length of 20 with a count of 1 is twenty coin tosses in a row, useful for probability exercises on streaks and runs.
  • Placeholder keys and IDs. A 128- or 256-bit string looks like a key for mockups and screenshots. It is not cryptographically random, so do not use it as an actual secret.

Reading binary quickly

Each position in a binary string is a power of two, counting from the right: 1, 2, 4, 8, 16, 32, 64, 128. To convert 01101001 to decimal, add the powers where a 1 appears: 64 + 32 + 8 + 1 = 105. Grouping bits in fours gives hexadecimal directly (0110 1001 becomes 0x69), which is why hex is the usual shorthand for long bit strings. An odd number in binary always ends in 1 and an even one in 0, so the Random Odd Number Generator and Random Even Number Generator are, in effect, choosing the last bit for you. For primes, which have no such shortcut, the Random Prime Number Generator tests each candidate. All of these are listed under all number generators.

Frequently asked questions

Why do some results start with 0?

Every bit, including the first, is a separate random choice, so a leading 0 is as likely as a leading 1. The results are fixed-width bit strings. If you need the top bit set, regenerate or change it by hand.

Can it show the decimal or hex value as well?

No. The output is binary only. Group the bits in fours to read off hex, or paste the string into a programming language or calculator that accepts a base-2 prefix (0b in Python and JavaScript).

Is the output random enough for cryptography?

No. The bits come from the browser's Math.random, which is fine for tests, teaching and games but is not a cryptographic source. Use a crypto library for keys and tokens.

What happens if I leave a field blank?

A blank length is replaced by a random number from 1 to 255 and a blank count by a random number from 1 to 63. The chosen values appear in the boxes after you press the button.