{"id":29066900,"url":"https://github.com/rhaiscript/rhai-rand","last_synced_at":"2025-06-27T10:08:53.921Z","repository":{"id":46027895,"uuid":"425722715","full_name":"rhaiscript/rhai-rand","owner":"rhaiscript","description":"Random numbers generation package for Rhai.","archived":false,"fork":false,"pushed_at":"2023-06-04T07:16:04.000Z","size":42,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-06-04T09:07:53.899Z","etag":null,"topics":["lib","random","random-generation","rhai","rhai-rand","scripting-language"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/rhai-rand","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhaiscript.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-08T06:29:31.000Z","updated_at":"2023-06-02T07:39:35.000Z","dependencies_parsed_at":"2023-01-20T09:01:46.368Z","dependency_job_id":null,"html_url":"https://github.com/rhaiscript/rhai-rand","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/rhaiscript/rhai-rand","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-rand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-rand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-rand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-rand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhaiscript","download_url":"https://codeload.github.com/rhaiscript/rhai-rand/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhaiscript%2Frhai-rand/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262235784,"owners_count":23279567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lib","random","random-generation","rhai","rhai-rand","scripting-language"],"created_at":"2025-06-27T10:08:53.176Z","updated_at":"2025-06-27T10:08:53.913Z","avatar_url":"https://github.com/rhaiscript.png","language":"Rust","readme":"`rhai-rand` - Package to Generate Random Numbers\n===============================================\n\n[![License](https://img.shields.io/crates/l/rhai)](https://github.com/license/rhaiscript/rhai-rand)\n[![crates.io](https://img.shields.io/crates/v/rhai-rand?logo=rust)](https://crates.io/crates/rhai-rand/)\n[![crates.io](https://img.shields.io/crates/d/rhai-rand?logo=rust)](https://crates.io/crates/rhai-rand/)\n\n[![Rhai logo](https://rhai.rs/book/images/logo/rhai-banner-transparent-colour.svg)](https://rhai.rs)\n\n`rhai-rand` is a [Rhai] package to provide random number generation using the [`rand`] crate.\n\n[Rhai] is an embedded scripting language and evaluation engine for Rust that gives a safe and easy way\nto add scripting to any application.\n\n\nUsage\n-----\n\n### `Cargo.toml`\n\n```toml\n[dependencies]\nrhai-rand = \"0.1\"\n```\n\n### [Rhai] script\n\n```js\n// Create random boolean\nlet decision = rand_bool();\n\nif decision {\n    // Create random number\n    let random_value = rand();\n    print(`Random number = ${random_value}`);\n} else {\n    print(\"Fixed number = 42\");\n}\n\n// Create array\nlet a = [1, 2, 3, 4, 5];\n\n// Shuffle it!\na.shuffle();\n\n// Now the array is shuffled randomly!\nprint(a);\n\n// Sample a random value from the array\nprint(a.sample());\n\n// Or sample multiple values\nprint(a.sample(3));\n```\n\n### Rust source\n\n```rust\n// packages::Package implements `as_shared_module`\n// which we need to register the RandomPackage\nuse rhai::{Engine, packages::Package};\nuse rhai_rand::RandomPackage;\n\n// Create Rhai scripting engine\nlet mut engine = Engine::new();\n\n// Create random number package and add the package into the engine\nengine.register_global_module(RandomPackage::new().as_shared_module());\n\n// Print 10 random numbers, each of which between 0-99!\nfor _ in 0..10 {\n    let value = engine.eval::\u003ci64\u003e(\"(rand() % 100).abs()\")?;\n\n    println!(\"Random number = {}\", value);\n}\n```\n\nAPI and Features\n----------------\n\nSee the online documentation.\n\n\n[Rhai]: https://rhai.rs\n[`rand`]: https://crates.io/crates/rand\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhaiscript%2Frhai-rand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhaiscript%2Frhai-rand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhaiscript%2Frhai-rand/lists"}