squirrel3-rs

Crates.iosquirrel3-rs
lib.rssquirrel3-rs
version0.1.2
sourcesrc
created_at2021-10-28 15:14:40.551307
updated_at2021-10-29 08:45:39.503585
descriptionSimple and reliable random number generator.
homepage
repositoryhttps://github.com/Descrout/squirrel3-rs
max_upload_size
id473602
size10,390
Adil Basar (Descrout)

documentation

README

squirrel3-rs

Simple and reliable; noise-based, random number generator.

Using; squirrel3 hashing function for the noise.

Usage

[dependencies]
squirrel3-rs = "0.1.2"
use squirrel3_rs::sq3;

fn main() {
    println!("{}", sq3::rand());
}

Examples

Basic:

println!("True or False => {}", sq3::bool());
println!("[0.0, 1.0) => {}", sq3::rand());
println!("[0, 100) => {}", sq3::u32(100));

Range:

println!("[2.14, 7.21) => {}", sq3::range_f32(2.14, 7.21));
println!("[-540, 2160) => {}", sq3::range_i32(-540, 2160));
// And more...

Array:

let mut fruits = vec!["apple", "banana", "peach", "orange", "strawberry"];
sq3::shuffle(&mut fruits);

println!("Shuffled: {:?}", fruits);
println!("I want to eat: {}", fruits[ sq3::usize(fruits.len()) ] );

Local State:

// Using manually created state, instead of thread_local.
let rng = sq3::Rng::new(2021 /*seed*/);
println!("True or False => {}", rng.bool());

Stateless Functions: ((No side effects))

// Original squirrel3
println!("[0, u32::MAX) => {}", sq3::squirrel3(3 /*position*/, 4 /*seed*/));
println!("[0, 1.0) => {}", sq3::normalized(3 /*position*/, 4 /*seed*/));

// Noise functions, returns a value between [0.0, 1.0)
println!("|x: 100| => {}", sq3::noise1d(100));
println!("|x: 100, y: 200| => {}", sq3::noise2d(100, 200));
println!("|x: 100, y: 200, z: 300| => {}", sq3::noise3d(100, 200, 300));

License

MIT

Commit count: 6

cargo fmt