#random #secure #entropy

stdrandom

Generate random numbers using standard library

2 unstable releases

new 0.2.0 May 1, 2025
0.1.0 May 1, 2025

#8 in #entropy

Download history 108/week @ 2025-04-25

118 downloads per month

Unlicense OR CC0-1.0

15KB
286 lines

Generate Random numbers using standard library

License Crates.io Crates.io MSRV Documentation Downloads

Overview

This Rust crate provides various random number generation utilities, including:

  • Random u32 and u64 generation.
  • Floating-point randomness (f32 and f64) in [0,1).
  • Random byte filling for buffers.
  • Random number from Range
  • Fast but lower-entropy alternatives using thread local RandomState.

Features

  • Minimal supported Rust version 1.56
  • 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_u64(), random_u32()

Generates a high entropy random number in a separate thread. These numbers have uniform distribution and pass chi square test.

fast_u64(), fast_u32()

Generates a lower entropy random number from current thread.

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()

Generate random number from specified range.

This code is released under a "No Copyright" license.

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.

No runtime deps