stdrandom 0.3.0-beta.2

Generate random numbers using only Rust standard library
Documentation
# Generate random numbers using only standard library


[![License](https://img.shields.io/crates/l/stdrandom)](https://unlicense.org)
[![Crates.io](https://img.shields.io/crates/v/stdrandom.svg)](https://crates.io/crates/stdrandom)
[![Crates.io MSRV](https://img.shields.io/crates/msrv/stdrandom?logo=rust&label=MSRV&labelColor=orange)](https://blog.rust-lang.org/2021/10/21/Rust-1.56.0/)
[![Dependency status](https://deps.rs/repo/gitlab/hsn10/stdrandom/status.svg)](https://deps.rs/repo/gitlab/hsn10/stdrandom)
[![Documentation](https://docs.rs/stdrandom/badge.svg)](https://docs.rs/stdrandom)
[![Lines of code](https://tokei.rs/b1/gitlab/hsn10/stdrandom?category=code)](https://github.com/XAMPPRocky/tokei)
[![Downloads](https://img.shields.io/crates/d/stdrandom)](https://crates.io/crates/stdrandom/versions)

## Overview

This Rust crate provides various **random number generation utilities**, including:
- Random **u8,u16,u32,u64,u128,usize** generation.
- Non negative **i8,i16,i32,i64,i128,isize** generation
- **Floating-point randomness** (`f32` and `f64`) in `[0,1)`.
- Random **byte filling** for buffers.
- Random **range filling** for slices.
- Random number generation from **Range**.
- **High entropy** random number generation by using separate thread `RandomState`.
- **Fast** but lower-entropy alternatives using thread local `RandomState`.

## Features

- Minimal supported Rust version **1.56**. Entire *2021 Rust edition* is supported.
- *No external dependencies* beyond standard Rust library.
- **Thread-based randomness**: Uses separate threads for improved entropy (`random_u64()`).
- **Secure and fast implementations** for generating random numbers.
- **Uniform distribution** ensured for floating-point values.

## Functions returning random numbers


### `random_u128(), random_u64(), random_u32(), random_u16(), random_u8(), random_usize()`

Generates a unsigned **high entropy random** number in a separate thread. These
numbers are unpredictable - true randoms.
Numbers have uniform distribution and pass chi square test with very good score.
While they are not certified for cryptographic purposes, they are good source of
randomness for seeding other random generators.

### `fast_u128(), fast_u64(), fast_u32(), fast_u16(), fast_u8(), fast_usize()`

Generates a **lower entropy random** number from the current thread.
This randomness is much faster and it still maintains a uniform distribution.
First number generated in the thread is fully random.
Internally, it uses SipHash13 with 2x64-bit internal state,
which is incremented by one on each call,
resulting in progressively lower randomness.

As expected, the chi square test score is *several times* worse than in the *random_* family.
While the chi square test is worse, it is still within the widely accepted limits for fast
random number generators.

These random numbers are definitely *not suitable* for generating cryptographic keys
or for applications where hash resistance is required.

### `random_f64(), random_f32()`

Generates a **high entropy random** floating point number in a separate thread
from in \[0, 1\) range. These numbers have uniform distribution
and pass chi square test.

### `fast_f32(), fast_f64()`

Generates a **lower entropy random** floating point number in \[0, 1\).

## Helper Functions


### `fill_bytes(), fill_numbers()`

Fills slice with random numbers with provided generator.

### `gen_range(), fill_range()`

Generate random number from specified range.

## 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/).