-
Notifications
You must be signed in to change notification settings - Fork 5
/
rng.rs
49 lines (43 loc) · 1.49 KB
/
rng.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use bevy::app::ScheduleRunnerSettings;
use bevy::prelude::*;
use bevy_rng::*;
use std::time::Duration;
fn main() {
// Don't register the plugin (non-deterministic)...
App::build()
.add_resource(ScheduleRunnerSettings::run_once())
.add_plugins(MinimalPlugins)
.add_system(random_number_1.system())
.add_system(random_number_2.system())
.run();
// ...don't provide a seed (same as above)...
App::build()
.add_resource(ScheduleRunnerSettings::run_once())
.add_plugins(MinimalPlugins)
.add_plugin(RngPlugin::default())
.add_system(random_number_1.system())
.add_system(random_number_2.system())
.run();
// ...seed from u64 (deterministic)...
App::build()
.add_resource(ScheduleRunnerSettings::run_once())
.add_plugins(MinimalPlugins)
.add_plugin(RngPlugin::from(42))
.add_system(random_number_1.system())
.add_system(random_number_2.system())
.run();
// ...or from a string (same as above).
App::build()
.add_resource(ScheduleRunnerSettings::run_loop(Duration::from_millis(100)))
.add_plugins(MinimalPlugins)
.add_plugin(RngPlugin::from("your seed here"))
.add_system(random_number_1.system())
.add_system(random_number_2.system())
.run();
}
fn random_number_1(mut rng: Local<Rng>) {
println!("1: {}", rng.gen::<f64>());
}
fn random_number_2(mut rng: Local<Rng>) {
println!("2: {}", rng.gen::<f64>());
}