drand48

Crates.iodrand48
lib.rsdrand48
version0.2.0
created_at2025-05-26 19:19:57.835251+00
updated_at2025-05-27 19:56:00.222386+00
descriptiondrand48 - POSIX.1 standard LCG random number generator
homepagehttps://gitlab.com/hsn10/drand48/
repositoryhttps://gitlab.com/hsn10/drand48.git
max_upload_size
id1690151
size27,703
Radim Kolar (hsn10)

documentation

README

drand48 POSIX.1 random number generator

License: Unlicense Crates.io Version MSRV Safe Rust Dependency Status Documentation Downloads Tokei

drand48 is the Linear Congruential Generator generator included in POSIX / ANSI-C standard employed by drand48() function family.

Parameters are: modulus m = 2^48, multiplier a = 25214903917, increment c = 11. Generator have full period 2^48.

Functions

Function next() returns full 48-bit output. Lower bits should be discarded because they have low distribution quality. How many bits you choose to discard depends on your quality needs.

POSIX compatible '48 functions:

  1. drand48 - returns f64 from [0,1)
  2. frand48 - returns f32 from [0,1) (not exists in POSIX standard)
  3. mrand48 - returns full range i32 - can be negative
  4. lrand48 - returns non negative i32
  5. srand48 - seeds generator using i32 POSIX method

Byte extracting functions

  1. get_bytes
  2. get_bytes3
  3. fill_bytes

16-bit conversion

We take the best top bits, discarding lower ones.

  1. get_i16
  2. get_u16

Seed functions

  1. validate_seed
  2. clamp_seed

Spectral test

2d 3d 4d 5d 6d 7d 8d
0.51 0.80 0.45 0.58 0.66 0.80 0.60

Compatibility

This version of drand48 matches outputs of drand() family in FreeBSD 13 libc.

No copyright

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.

Unlicense logo

Commit count: 0

cargo fmt