User Rating 0.0
Total Usage 0 times
1 – 128 bits
1 – 500,000
Is this tool helpful?

Your feedback helps us improve.

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.

binary generator random binary numbers bit string generator binary converter number generator

Formulas

Each binary string of length n is constructed by sampling n independent bits from the CSPRNG. The decimal equivalent of a binary string bn1bn2b0 is computed as:

D = n1i=0 bi 2i

Hexadecimal conversion groups bits into 4-bit nibbles from the LSB, padding the MSB group with zeros if n is not divisible by 4:

Hk = 3j=0 b4k+j 2j

When uniqueness is enforced, the maximum number of unique values is 2n (or 2n1 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:

E[T] N ln(NN m)

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 DigitsCommon Use
120 - 11Boolean flag, coin flip
4160 - 151Single hex nibble
82560 - 2552Byte, ASCII character code
101,0240 - 1,0233Kilobyte addressing
124,0960 - 4,0953Color channel (12-bit DAC)
1665,5360 - 65,5354Unsigned short, TCP port
201,048,5760 - 1,048,5755Address segment (20-bit real mode)
2416,777,2160 - 16,777,2156RGB color (24-bit true color)
324,294,967,2960 - 4,294,967,2958IPv4 address, 32-bit integer
482.81 × 10140 - 281,474,976,710,65512MAC address
539.01 × 10150 - 9,007,199,254,740,99114JS safe integer limit
641.84 × 10190 - 18,446,744,073,709,551,61516Long integer, memory address
1283.40 × 10380 - 3.40 × 103832UUID, IPv6 address, AES key

Frequently Asked Questions

Each bit is sourced from 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.
The tool automatically caps the count at 2n (or 2n1 with the leading-one constraint, since MSB is fixed). A toast notification informs you of the adjustment. For example, requesting 300 unique 8-bit numbers is impossible since only 256 exist. The generator will produce all 256 in random order.
A random n-bit number may have leading zeros, making its effective bit length less than n. For instance, 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).
JavaScript's 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.
No. The CSPRNG is non-deterministic by design and does not accept a seed value. For reproducible sequences, you would need a seeded PRNG like a linear congruential generator or xorshift. This tool prioritizes statistical quality over reproducibility. If you need a specific set preserved, use the download feature to save results as a .txt file.
The generator chunks output in batches of 5,000 to avoid blocking the UI thread. On modern hardware, generating 100,000 32-bit unique values completes in under 3 seconds. The bottleneck is uniqueness checking via a 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.