# drand48 POSIX.1 random number generator
[](https://unlicense.org/)
[](https://crates.io/crates/drand48)
[](https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html)
[](https://doc.rust-lang.org/nomicon/meet-safe-and-unsafe.html)
[](https://deps.rs/repo/gitlab/hsn10/drand48)
[](https://docs.rs/drand48)
[](https://crates.io/crates/drand48/versions)
[](https://github.com/XAMPPRocky/tokei)
*drand48* is the Linear Congruential Generator generator
[included](https://pubs.opengroup.org/onlinepubs/7908799/xsh/drand48.html)
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)
1. frand48 - returns f32 from \[0,1) (not exists in POSIX standard)
1. mrand48 - returns full range i32 - can be negative
1. lrand48 - returns non negative i32
1. srand48 - seeds generator using i32 POSIX method
### Byte extracting functions
1. get_bytes
1. get_bytes3
1. fill_bytes
### 16-bit conversion
We take the best top bits, discarding lower ones.
1. get_i16
1. get_u16
### Seed functions
1. validate_seed
1. clamp_seed
## Spectral test
| 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](https://creativecommons.org/publicdomain/zero/1.0/) OR [Unlicense](http://unlicense.org/).
