[][src]Crate randomize

A dead simple to use randomization library for rust.

Compiles and works on the GBA.

Basic Usage

use randomize::pcg::{PCGPickU64, PCGMemU64, PCGPhantomU64};
use typenum::consts::U5;

// On `x86` family CPUs we can seed from the CPU counter.
#[cfg(any(target_arch = "x86",target_arch = "x86_64"))]
let u: u64 = randomize::u64_from_rdtsc();

// On other CPUs you'll need to get a seed from somewhere.
#[cfg(not(any(target_arch = "x86",target_arch = "x86_64")))]
let u: u64 = 1776;

let pick_gen = &mut PCGPickU64::seed(u, u);
let mem_gen = &mut PCGMemU64::seed(u);
let phantom_gen: &mut PCGPhantomU64<U5> = &mut PCGPhantomU64::seed(u);

println!("{}", pick_gen.next_u32());

NOT FOR CRYPTOGRAPHIC PURPOSES.

The crate is specific to my personal needs for building games and such. I don't want to, or try to, cover all use cases. If you need a highly general crate for randomization you should use the rand crate, which is the "official" way to do randomization in rust.

Re-exports

pub use self::mcg::*;
pub use self::pcg::*;
pub use self::bounded::*;

Modules

bounded

Module for bounded randomization.

lcg

Functions for Linear Congruential Generators.

mcg[
Deprecated
]

Module for MCGs with permuted output.

noncg

PRNGs that aren't any kind of congruential generator.

pcg

PCG related things.

Functions

u64_from_rdtsc

Calls rdtsc to get a semi-arbitrary u64 value.