rhai-rand
: Random Number Generation, Shuffling and Sampling
rhai-rand
is an independent Rhai package that provides:
See https://docs.rs/rhai-rand for the list of functions.
On
crates.io
:rhai-rand
On
GitHub
:rhaiscript/rhai-rand
Package name:
RandomPackage
Dependency
Cargo.toml
:
[dependencies]
rhai = "1.20.0"
rhai-rand = "0.1" # use rhai-rand crate
Load Package into Engine
use rhai::Engine;
use rhai::packages::Package; // needed for 'Package' trait
use rhai_rand::RandomPackage;
let mut engine = Engine::new();
// Create new 'RandomPackage' instance
let random = RandomPackage::new();
// Load the package into the `Engine`
random.register_into_engine(&mut engine);
Features
Feature | Description | Default? | Should not be used with Rhai feature |
---|---|---|---|
float | enables random floating-point number generation | yes | no_float |
array | enables methods for arrays | yes | no_index |
metadata | enables functions metadata (turns on metadata in Rhai) | no |
Cargo.toml
:
[dependencies]
# Rhai is set for 'no_float', meaning no floating-point support
rhai = { version="1.20.0", features = ["no_float"] }
# Use 'default-features = false' to clear defaults, then only add 'array'
rhai-rand = { version="0.1", default-features = false, features = ["array"] }