Hawkynt

Knuth-B

Algorithm B from Knuth’s The Art of Computer Programming, Volume 2. Implements a shuffle algorithm that wraps the minstd_rand0 linear congruential generator with a 256-entry table to improve randomness by breaking sequential correlations. Used in C++ standard library as shuffle_order_engine<minstd_rand0, 256>.

Properties

Property Value
Category Random Number Generators
Sub-category Shuffle Algorithm
Security status πŸŽ“ Educational Only
Complexity Intermediate
Inventor Donald Knuth
Year 1969
Origin πŸ‡ΊπŸ‡Έ United States
Source algorithms/random/knuth-b.js

Parameters

Parameter Supported values
Seed sizes 4 bytes (32 bits)

Capabilities

Flag Value
IsDeterministic Yes
IsCryptographicallySecure No

Security

Status: πŸŽ“ Educational Only

No vulnerabilities are recorded for this implementation.

Documentation

References

Test vectors

3 vectors ship with this algorithm and run in the test suite. Byte values are hexadecimal.

Vector 1 β€” C++ std::knuth_b with seed=1, first 10 values

Field Value
seed 00000001
outputSize 40
input null
expected 09189c643113c3982278fd06795056c4 3bd814d710b1d72c061351336a5d128c 38532fd146fc9a81

Vector 2 β€” C++ std::knuth_b canonical test: 10,000th value from seed=1 = 1112339016

Field Value
seed 00000001
count 10000
outputSize 4
input null
expected 424cf248

Vector 3 β€” C++ std::knuth_b with seed=123456789, first 5 values

Field Value
seed 075bcd15
outputSize 20
input null
expected 704f3a22744474f72de9c635557bd4a46c9e4484

← All algorithms