4 releases
| 0.9.1-alpha.3 | May 29, 2025 |
|---|---|
| 0.9.1-alpha.2 | May 24, 2025 |
| 0.9.1-alpha.1 | May 23, 2025 |
| 0.9.0 | Aug 2, 2024 |
#356 in Math
54KB
863 lines
4BSD libc random number generator
Linear congruential generator LCG with modulus m = 2^31, multiplier a = 1103515245 and increment c = 12345. Outputs 31 bits of randomness with more randomness in higher bits. Generator have full 2^31 period.
Features
- Classic BSD / VAX / ANSI-C C library random number generator.
- 15-bit K&R version included
- Zero dependencies.
- Safe Rust.
- Non viral BSD-3 License.
- libc style API.
References
This generator is listed in OESIS database as A096553.
15-bit version
- https://oeis.org/A061364 - seed 1
- https://oeis.org/A096554 - seed 0
Licensing
This package uses Revised BSD license.
Originally 4.4BSD-Lite2 got released under BSD-4 but it got relicensed as BSD-3. Advertising cause got removed. More info at: https://www.dragonflybsd.org/docs/developer/DragonFly_BSD_License/
Credits
This product includes software developed by the University of California, Berkeley and its contributors.
Upstream code
Code comes and is tested against 4.4BSD stdlib
- https://github.com/sergev/4.4BSD-Lite2/tree/master/usr/src/lib/libc/stdlib
- https://github.com/freebsd/freebsd-src/blob/releng/4.11/lib/libc/stdlib/rand.c
- https://cvsweb.openbsd.org/src/lib/libc/stdlib/
- https://github.com/NetBSD/src/blob/trunk/lib/libc/stdlib/rand.c
- https://gitweb.dragonflybsd.org/dragonfly.git/tree/5daa25b05ec172803258b0c1f1148cadfccdba9e:/lib/libc/stdlib
History
- Included in 2.9BSD, 3BSD and 4BSD, 4.1cBSD libc.
- Included in SysVR4.
- Included in AT&T Bell Labs V7, V7M and V9.
- Included in AT&T's Unix Support Group (USG) SysIII.
- SunOS 4.1, OpenSolaris compat-4.1 library.
- Included in Ultrix-3.1.
- Included in 4.1-compat part of 4.2BSD libc.
- Its not clear yet in which BSD version this random number generator first appeared.
- 4.2BSD documentation talks about weakness of this generator. I believe they wanted to replace it with something else.
- They removed it from main BSD libc and left it only in backward 4.1-compat library.
- In 4.3BSD-Tahoe it is still in 4.1-compat.
- In 2.11BSD (Last 16 bit BSD PDP-11 distribution) it is in 4.1-compat.
- In 4.3BSD-Reno generator is part of main libc again.
- FreeBSD 5 replaced this algorithm with minstd0.
- DragonFlyBSD merged FreeBSD change.
- It is still in current NetBSD-10 source tree.
- It is still in OpenBSD source tree.
- Included in glibc-2.26
- Standard C library (VAX C)
- It is backend of K&R stdlib 15-bit rand().