#gamedev #random #rng

no-std perchance

Very simple random number generation optimized for ease of use

8 unstable releases (3 breaking)

Uses new Rust 2021

0.4.0 Nov 23, 2022
0.3.2 Oct 8, 2022
0.3.1 May 3, 2022
0.3.0 Apr 5, 2022
0.1.1 Feb 19, 2022

#149 in Algorithms

Download history 395/week @ 2022-08-14 501/week @ 2022-08-21 563/week @ 2022-08-28 698/week @ 2022-09-04 789/week @ 2022-09-11 894/week @ 2022-09-18 836/week @ 2022-09-25 1140/week @ 2022-10-02 1195/week @ 2022-10-09 1407/week @ 2022-10-16 1328/week @ 2022-10-23 1633/week @ 2022-10-30 1702/week @ 2022-11-06 893/week @ 2022-11-13 721/week @ 2022-11-20 695/week @ 2022-11-27

4,023 downloads per month
Used in 6 crates (via cervo-core)

MIT/Apache

24KB
320 lines

🎲 perchance

A lightweight, quick, and easy-to-use library for generating and using randomness, designed for the most common use cases you find in games and geometry.

Note that perchance is not cryptographically secure and should not be used in contexts where security is a concern.

Usage

perchance is a simple random number generation library, tuned for ease of use: create an instance of PerchanceContext and go.

let mut rng = perchance::PerchanceContext::new(seed);

let between_0_and_1 = rng.uniform_f32();
let dice_roll = rng.uniform_range_i32(1..=6);
let random_direction = rng.uniform_sphere_surface_vec3();
let thing_should_happen = rng.get_bool();

enum Event {
    Thing1,
    Thing2,
    Thing3,
}
let which_should_happen = rng.choose(&[Event::Thing1, Event::Thing2, Event::Thing3]);

You can also use the global perchance::global() if you have the std feature enabled:

// Seed the global context first. You may do so manually, or, on platforms that support it,
// obtain a seed to pass into it by calling `perchance::gen_time_seed()`.
perchance::seed_global(0x5F3759DF); // ;)

let mut rng = perchance::global();
let between_0_and_1 = rng.uniform_f32();

Contributing

We welcome community contributions to this project.

Please read our Contributor Guide for more information on how to get started.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.5MB
~58K SLoC