drand48 POSIX.1 random number generator
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:
- drand48 - returns f64 from [0,1)
- frand48 - returns f32 from [0,1) (not exists in POSIX standard)
- mrand48 - returns full range i32 - can be negative
- lrand48 - returns non negative i32
- srand48 - seeds generator
Byte extracting functions
- get_bytes
- get_bytes3
- fill_bytes
16-bit conversion
We take the best top bits, discarding lower ones.
- get_i16
- get_u16
Seed functions
- validate_seed
- 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.
![]()