#numbers #generator #tiny #secure

tiny-rng

Tiny RNG, a minimal random number generator

2 unstable releases

0.2.0 Apr 5, 2021
0.1.0 Jun 4, 2019

#89 in #tiny

Download history 5/week @ 2024-01-08 18/week @ 2024-01-15 6/week @ 2024-02-12 20/week @ 2024-02-19 24/week @ 2024-02-26 17/week @ 2024-03-04 15/week @ 2024-03-11 14/week @ 2024-03-18 5/week @ 2024-03-25 60/week @ 2024-04-01 10/week @ 2024-04-15

78 downloads per month
Used in rsevents

CC0 license

8KB
142 lines

Tiny RNG, a minimal random number generator

Warning: Not cryptographically secure.

Examples:

use tiny_rng::{Rng, Rand};

fn main() {
    let mut rng = Rng::from_seed(0);
  
    println!("A u32 random number: 0x{:08x}", rng.rand_u32());
    println!("Throw a dice: {}", rng.rand_range_u32(1, 6));

    let a: Vec<u32> = rng.iter(Rand::rand_u32).take(4).collect();
    println!("An array of u32 random numbers: {:08x?}", a);
    
    let a: Vec<u32> = rng.iter(|rng| rng.rand_range_u32(1, 6))
        .take(4).collect();
    println!("An array of dice samples: {:?}", a);

    let mut a: Vec<u32> = (0..10).collect();
    rng.shuffle(&mut a);
    println!("A shuffled array: {:?}", a);
    
    let mut a: [u8;4] = [0, 0, 0, 0];
    rng.fill(&mut a);
    println!("Random bytes: {:?}", a);
}

lib.rs:

Tiny RNG, a minimal random number generator

Warning: Not cryptographically secure.

No runtime deps