[][src]Crate rand_facade

A cursed facade for using / sharing a RngCore implementation between components using a global random instance and some RAII tricks.

use std::pin::Pin;
use rand::{RngCore, SeedableRng};
use rand_chacha::ChaChaRng;
use rand_facade::GlobalRng;

// Create new RNG instance (DO NOT USE A STATIC SEED IRL)
let mut chacha_rng = ChaChaRng::from_seed([1u8; 32]);
 
// Bind in to global RNG
let _rng_guard = GlobalRng::set(Pin::new(&mut chacha_rng));
 
// Use global RNG instances
let _rand = GlobalRng::get().next_u32();
 

Structs

GlobalRng

Wrapper providing mutex backed access to a global RNG instance

RngGuard

Guard type holding the bound rng, when this is dropped the global RNG will become unavailable

Traits

Rng

Rng trait requires both RngCore and CryptoRng