Module bevy_math::sampling::standard

source ·
Expand description

This module holds local implementations of the Distribution trait for Standard, which allow certain Bevy math types (those whose values can be randomly generated without additional input other than an Rng) to be produced using rand’s APIs. It also holds FromRng, an ergonomic extension to that functionality which permits the omission of type annotations.

For instance:

let mut rng = StdRng::seed_from_u64(7313429298);
// Random direction using thread-local rng
let random_direction1: Dir3 = random();

// Random direction using the rng constructed above
let random_direction2: Dir3 = rng.gen();

// The same as the previous but with different syntax
let random_direction3 = Dir3::from_rng(&mut rng);

// Five random directions, using Standard explicitly
let many_random_directions: Vec<Dir3> = rng.sample_iter(Standard).take(5).collect();

Traits§

  • Ergonomics trait for a type with a Standard distribution, allowing values to be generated uniformly from an Rng by a method in its own namespace.