cu-rng 1.1.1

Seedable pseudo-random number generator resource for Copper.
docs.rs failed to build cu-rng-1.1.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: cu-rng-1.1.0

Seeded pseudo-random number generator resource for Copper.

[CuRng] is a deterministic, reproducible RNG (ChaCha8) usable anywhere [rand::Rng] is expected. It is wired into a Copper app as a single-slot resource bundle, [CuRngBundle], via the standard resource mechanism.

Use [prelude] to bring the normal rand sampling API into scope:

use cu_rng::prelude::*;

let mut rng = CuRng::from_seed(12345);
let unit_f64: f64 = rng.random();
let unit_f32: f32 = rng.random();
let noise: f64 = rng.random_range(-0.05..0.05);
let enabled: bool = rng.random();
let dropout: bool = rng.random_bool(0.02);
let vector: [f32; 3] = rng.random();

assert!((0.0..1.0).contains(&unit_f64));
assert!((0.0..1.0).contains(&unit_f32));
assert!((-0.05..0.05).contains(&noise));
let _ = (enabled, dropout, vector);

Example config

(
    resources: [
        ( id: "planner_rng", provider: "cu_rng::CuRngBundle", config: {"seed": 12345} ),
    ],
    tasks: [
        ( id: "planner", type: "tasks::MyPlanner",
          resources: { "rng": "planner_rng.rng" } ),
    ],
)

On the task side, declare the binding with the resources! macro:

use cu29::prelude::*;
use cu29::resources;
use cu_rng::prelude::*;

mod planner_resources {
    use super::*;
    resources!({ rng => Owned<CuRng> });
}