Random Nibbles Generator
Generate cryptographically random nibbles (4-bit values 0-15) in binary, hex, decimal, and octal formats with frequency analysis.
About
A nibble (also nybble) is a 4-bit aggregation - half an octet. Its value domain spans 0 to 15 (0x0 - 0xF). Nibbles are the atomic unit of hexadecimal notation: every hex digit encodes exactly one nibble. In memory-mapped I/O, BCD arithmetic, and legacy telecom protocols (SMS PDU encoding), nibble-level manipulation is routine. Generating nibbles with a weak PRNG (Math.random) produces statistically biased output unsuitable for key material, nonce construction, or Monte Carlo sampling. This tool uses the browser's crypto.getRandomValues CSPRNG, seeded from OS entropy, which satisfies NIST SP 800-90A requirements.
Each generated value is masked to 4 bits via bitwise AND with 0x0F, discarding the upper nibble of each random byte. The tool computes Shannon entropy H across the output set. For a uniform distribution over 16 symbols, maximum entropy is 4.0 bits. Deviations indicate sampling artifacts at small sample sizes. Generate at least 256 nibbles to observe convergence toward uniformity. Note: this tool approximates statistical quality for visual inspection only - it does not replace NIST STS or Diehard test suites.
Formulas
Each nibble is extracted from a cryptographically random byte by masking the upper four bits:
This isolates bits 0 - 3, yielding a uniform value in [0, 15]. Shannon entropy for the generated set is computed as:
where p(i) = count(i)N is the observed frequency of nibble value i in N total samples. For a perfectly uniform distribution across 16 symbols, Hmax = log2(16) = 4.0 bits. The ratio HHmax expresses efficiency of the source. Values below 0.95 at N โฅ 256 suggest non-uniformity.
Reference Data
| Nibble (Dec) | Binary | Hex | Octal | BCD Digit | ASCII Char (0x30+n) | 7-Segment Code |
|---|---|---|---|---|---|---|
| 0 | 0000 | 0 | 00 | 0 | 0 (0x30) | 0x3F |
| 1 | 0001 | 1 | 01 | 1 | 1 (0x31) | 0x06 |
| 2 | 0010 | 2 | 02 | 2 | 2 (0x32) | 0x5B |
| 3 | 0011 | 3 | 03 | 3 | 3 (0x33) | 0x4F |
| 4 | 0100 | 4 | 04 | 4 | 4 (0x34) | 0x66 |
| 5 | 0101 | 5 | 05 | 5 | 5 (0x35) | 0x6D |
| 6 | 0110 | 6 | 06 | 6 | 6 (0x36) | 0x7D |
| 7 | 0111 | 7 | 07 | 7 | 7 (0x37) | 0x07 |
| 8 | 1000 | 8 | 10 | 8 | 8 (0x38) | 0x7F |
| 9 | 1001 | 9 | 11 | 9 | 9 (0x39) | 0x6F |
| 10 | 1010 | A | 12 | Invalid | : (0x3A) | 0x77 |
| 11 | 1011 | B | 13 | Invalid | ; (0x3B) | 0x7C |
| 12 | 1100 | C | 14 | Invalid | < (0x3C) | 0x39 |
| 13 | 1101 | D | 15 | Invalid | = (0x3D) | 0x5E |
| 14 | 1110 | E | 16 | Invalid | > (0x3E) | 0x79 |
| 15 | 1111 | F | 17 | Invalid | ? (0x3F) | 0x71 |