Crates.io | mcg59 |
lib.rs | mcg59 |
version | 0.9.4 |
created_at | 2025-05-24 21:52:27.93384+00 |
updated_at | 2025-05-26 18:17:17.615194+00 |
description | MCG59 random number generator |
homepage | https://gitlab.com/hsn10/mcg59 |
repository | https://gitlab.com/hsn10/mcg59.git |
max_upload_size | |
id | 1687771 |
size | 30,787 |
Generator parameters are modulus m = 2^59, multiplier a = 13^13, c = 0. Period is 2^57, output have 59bits.
Generator needs to be seeded with nonzero, odd number. Provided function clamp_seed
will
take care of that.
Lower bits have low randomness and should be discarded. Highest 27 bits are top quality, passing known statistical tests. This is enough bits for representing fp32 [0,1).
You can take more bits for progresively worse statistic results. Taking 40 bits of MCG59 still beats MCG31 (minstd) generator. Because MCG59 have larger period as well, it is suitable minstd replacement.
Generator natively generates 59 output bits with 2^57 period.
Conversion functions are provided for converting generated i64 value into array 3 or 5 bytes, i32, u32, i16, u16, f32, f64 discarding lowest bits.
Another function is provided for filling byte slice using 5 bytes chunks.
2d | 3d | 4d | 5d | 6d | 7d | 8d | 9d |
---|---|---|---|---|---|---|---|
0.8423 | 0.7288 | 0.7426 | 0.5771 | 0.6351 | 0.5217 | 0.5455 | 0.56 |
Value 0.75 or higher is considered good enough to pass spectral test. Spectral test do not include discarding lower bits.
This is free and unencumbered software released into the public domain.
You may use, modify, distribute, and contribute to this code without restriction. To the extent possible under law, the author(s) of this work waive all copyright and related rights.
Licensed under CC0-1.0 OR Unlicense.