bsd4random

Crates.iobsd4random
lib.rsbsd4random
version0.9.1-alpha.3
created_at2024-08-02 06:14:29.137763+00
updated_at2025-05-29 21:28:08.511045+00
description4.1BSD libc random number generator
homepagehttps://gitlab.com/hsn10/bsd4random
repositoryhttps://gitlab.com/hsn10/bsd4random.git
max_upload_size
id1322874
size83,885
Radim Kolar (hsn10)

documentation

README

4BSD libc random number generator

Crates.io License Crates.io Version Crates.io MSRV Safe Rust dependency status Documentation Downloads LOC

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

  1. Classic BSD / VAX / ANSI-C C library random number generator.
  2. 15-bit K&R version included
  3. Zero dependencies.
  4. Safe Rust.
  5. Non viral BSD-3 License.
  6. libc style API.

References

This generator is listed in OESIS database as A096553.

15-bit version

  1. https://oeis.org/A061364 - seed 1
  2. 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

  1. https://github.com/sergev/4.4BSD-Lite2/tree/master/usr/src/lib/libc/stdlib
  2. https://github.com/freebsd/freebsd-src/blob/releng/4.11/lib/libc/stdlib/rand.c
  3. https://cvsweb.openbsd.org/src/lib/libc/stdlib/
  4. https://github.com/NetBSD/src/blob/trunk/lib/libc/stdlib/rand.c
  5. https://gitweb.dragonflybsd.org/dragonfly.git/tree/5daa25b05ec172803258b0c1f1148cadfccdba9e:/lib/libc/stdlib

History

  1. Included in 2.9BSD, 3BSD and 4BSD, 4.1cBSD libc.
  2. Included in SysVR4.
  3. Included in AT&T Bell Labs V7, V7M and V9.
  4. Included in AT&T's Unix Support Group (USG) SysIII.
  5. SunOS 4.1, OpenSolaris compat-4.1 library.
  6. Included in Ultrix-3.1.
  7. 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.
  8. FreeBSD 5 replaced this algorithm with minstd0.
  9. DragonFlyBSD merged FreeBSD change.
  10. It is still in current NetBSD-10 source tree.
  11. It is still in OpenBSD source tree.
  12. Included in glibc-2.26
  13. Standard C library (VAX C)
  14. It is backend of K&R stdlib 15-bit rand().
Commit count: 0

cargo fmt