rhai-rand
- Package to Generate Random Numbers
rhai-rand
is a Rhai package to provide random number generation using the rand
crate.
Rhai is an embedded scripting language and evaluation engine for Rust that gives a safe and easy way to add scripting to any application.
Usage
Cargo.toml
[]
= "0.1"
Rhai script
// Create random boolean
let decision = ;
if decision else
// Create array
let a = ;
// Shuffle it!
a.;
// Now the array is shuffled randomly!
;
// Sample a random value from the array
;
// Or sample multiple values
;
Rust source
// packages::Package implements `as_shared_module`
// which we need to register the RandomPackage
use ;
use RandomPackage;
// Create Rhai scripting engine
let mut engine = new;
// Create random number package and add the package into the engine
engine.register_global_module;
// Print 10 random numbers, each of which between 0-99!
for _ in 0..10
API and Features
See the online documentation.