Format Code Now
/
Random generatorsRandom Binary Number Generator Next: Random Fraction Generator ›

Random Binary Number Generator

RG-18

Choose a bit length and a count to get random binary numbers such as 01101001. Every bit is an independent fair coin flip, and leading zeros are kept.

Runs in your browser. Nothing is uploaded.

Optional: a bit length from 1 to 4096. Empty uses the Length choice.

Random binary numbers

How to use it

  1. Pick a length in bits, or type any length from 1 to 4096 in the box.
  2. Choose how many numbers you want.
  3. Optionally tick First bit is always 1, Group in fours, or Add 0b prefix.
  4. Press Generate binary and copy the list.

How the bits are made

Bits come from crypto.getRandomValues, the secure random source in your browser. Each bit is independent and equally likely to be 0 or 1. The tool builds each number from chunks of up to 32 bits and pads every chunk, so a number always has exactly the length you chose and leading zeros are kept. An 8-bit result such as 00101101 is eight characters, not six.

Options that change the output

First bit is always 1 fixes the top bit, which gives a value that uses the full width; the other bits stay random. Group in fours inserts a space between groups of four bits, counted from the right, so a 10-bit number reads as 00 1010 1101. Add 0b prefix writes 0b in front, as many programming languages do. The output is text only. The tool does not convert to decimal or hex.

Error messages and what to do

MessageWhat it meansFix
The bit length must be between 1 and 4096.The length typed in the box is 0 or above 4096.Use a whole number from 1 to 4096.
Type a bit length as a whole number from 1 to 4096, or leave the box empty.The box holds something other than digits.Type only a number, or clear the box to use the Length choice.

Questions people ask

How do I generate a random 8-bit binary number?

Set Length to 8, How many to 1, and press Generate binary. You get something like 10110010, always eight digits. To get a full byte range, leave First bit is always 1 unticked so values start with 0 as often as with 1.

Can I choose a length that is not 8, 16 or 32?

Yes. Type any whole number from 1 to 4096 in the box. A value in the box overrides the Length choice. Clear the box to go back to the choice.

Are leading zeros kept?

Yes. Every number has exactly the chosen number of bits, so 0001 stays four digits. If you want values that never start with zero, tick First bit is always 1.

Can the same number appear twice?

It can, since each number is drawn on its own. For long numbers a repeat is practically impossible, but for 4 bits there are only 16 values, so repeats are common when you ask for many.

Is this random enough for keys?

The bits come from the browser secure random source, which is the right kind of source for keys. Even so, do not paste a real secret key from any web page into production. Use a key tool made for that job and generate keys on the machine that will use them.

How do I convert the result to decimal?

This tool only writes binary text. Copy the number into a binary to decimal converter. In code, parseInt(bits, 2) works for up to 53 bits, and BigInt("0b" + bits) works for longer ones.

About this tool

Values are made in your browser with crypto.getRandomValues and rejection sampling, so no value is favored, and nothing is sent anywhere or stored. Each bit is an independent fair coin flip, and every number is written with exactly the length you chose, so leading zeros are kept (00101101 and not 101101). Turn on "First bit is always 1" if you need the value to use the full width; the top bit is then fixed and the other bits stay random. Grouping splits the digits into fours from the right, with a space between groups. Output is text only: the tool does not convert to decimal; use the binary converter for that. Lengths up to 4096 bits are accepted.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.