Crates.io | squirrel3-rs |
lib.rs | squirrel3-rs |
version | 0.1.2 |
source | src |
created_at | 2021-10-28 15:14:40.551307 |
updated_at | 2021-10-29 08:45:39.503585 |
description | Simple and reliable random number generator. |
homepage | |
repository | https://github.com/Descrout/squirrel3-rs |
max_upload_size | |
id | 473602 |
size | 10,390 |
Simple and reliable; noise-based, random number generator.
Using; squirrel3 hashing function for the noise.
[dependencies]
squirrel3-rs = "0.1.2"
use squirrel3_rs::sq3;
fn main() {
println!("{}", sq3::rand());
}
println!("True or False => {}", sq3::bool());
println!("[0.0, 1.0) => {}", sq3::rand());
println!("[0, 100) => {}", sq3::u32(100));
println!("[2.14, 7.21) => {}", sq3::range_f32(2.14, 7.21));
println!("[-540, 2160) => {}", sq3::range_i32(-540, 2160));
// And more...
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()) ] );
// Using manually created state, instead of thread_local.
let rng = sq3::Rng::new(2021 /*seed*/);
println!("True or False => {}", rng.bool());
// 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));