Binary Numbers Generator
Generate random binary numbers with configurable bit length, count, uniqueness, and output formats. Copy or download results instantly.
About
Generating binary strings by hand or through naive Math.random calls introduces statistical bias. Bit sequences that appear uniform often fail frequency and runs tests, corrupting Monte Carlo simulations, cryptographic key material, or hardware test vectors. This tool uses crypto.getRandomValues, the browser's CSPRNG backed by OS entropy, to produce each bit independently with probability p = 0.5. You control the bit width n from 1 to 128 bits and can enforce uniqueness, which matters when the sample space 2n is small relative to the requested count.
Output formats include raw binary, hexadecimal (0x prefix), octal, and decimal. For bit lengths exceeding 53, the decimal conversion uses BigInt to avoid IEEE 754 precision loss. The tool approximates true uniform distribution under the assumption that the underlying OS entropy pool is adequately seeded. Note: requesting more unique values than 2n is mathematically impossible and will be capped automatically.
Formulas
Each binary string of length n is constructed by sampling n independent bits from the CSPRNG. The decimal equivalent of a binary string bn−1bn−2…b0 is computed as:
Hexadecimal conversion groups bits into 4-bit nibbles from the LSB, padding the MSB group with zeros if n is not divisible by 4:
When uniqueness is enforced, the maximum number of unique values is 2n (or 2n−1 with leading-one constraint). The expected number of CSPRNG calls to fill a set of size m from a pool of N follows the coupon collector approximation:
Where D = unsigned decimal value, bi = bit at position i (0 or 1), n = bit length, Hk = value of hex digit k, N = total pool size 2n, m = requested unique count, E[T] = expected random trials needed.
Reference Data
| Bit Length (n) | Possible Values (2n) | Range (Unsigned Decimal) | Hex Digits | Common Use |
|---|---|---|---|---|
| 1 | 2 | 0 - 1 | 1 | Boolean flag, coin flip |
| 4 | 16 | 0 - 15 | 1 | Single hex nibble |
| 8 | 256 | 0 - 255 | 2 | Byte, ASCII character code |
| 10 | 1,024 | 0 - 1,023 | 3 | Kilobyte addressing |
| 12 | 4,096 | 0 - 4,095 | 3 | Color channel (12-bit DAC) |
| 16 | 65,536 | 0 - 65,535 | 4 | Unsigned short, TCP port |
| 20 | 1,048,576 | 0 - 1,048,575 | 5 | Address segment (20-bit real mode) |
| 24 | 16,777,216 | 0 - 16,777,215 | 6 | RGB color (24-bit true color) |
| 32 | 4,294,967,296 | 0 - 4,294,967,295 | 8 | IPv4 address, 32-bit integer |
| 48 | 2.81 × 1014 | 0 - 281,474,976,710,655 | 12 | MAC address |
| 53 | 9.01 × 1015 | 0 - 9,007,199,254,740,991 | 14 | JS safe integer limit |
| 64 | 1.84 × 1019 | 0 - 18,446,744,073,709,551,615 | 16 | Long integer, memory address |
| 128 | 3.40 × 1038 | 0 - 3.40 × 1038 | 32 | UUID, IPv6 address, AES key |
Frequently Asked Questions
crypto.getRandomValues(), which draws from the operating system's CSPRNG (e.g., /dev/urandom on Linux, BCryptGenRandom on Windows). Each byte provides 8 independent bits, and we extract exactly n bits per number. Unlike Math.random(), which uses a PRNG with a 128-bit internal state and can exhibit correlations in the lower bits, the CSPRNG provides cryptographic-quality entropy suitable for key generation and simulation seeding.00101011 is technically a 6-bit number. Forcing MSB to 1 guarantees every result uses the full n-bit width. This is critical when generating cryptographic primes, fixed-width register test patterns, or when bit length determines protocol field boundaries (e.g., a 16-bit identifier that must occupy exactly 2 bytes).Number type is IEEE 754 double-precision, safely representing integers up to 253 − 1 (9,007,199,254,740,991). For n > 53, this tool uses BigInt arithmetic to compute the exact decimal value without precision loss. The output string will carry the full integer representation. Browsers without BigInt support (pre-2020) will see a graceful fallback message..txt file.Set, which approaches O(m ⋅ n) for string hashing. For non-unique generation, throughput is essentially linear. Maximum count is capped at 500,000 to prevent browser memory issues.