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
#![cfg_attr(windows, deny(unsafe_code))]
#![cfg_attr(not(windows), forbid(unsafe_code))]
#[cfg(feature = "std")]
pub mod entropy;
pub mod rand;
pub use rand::*;
use core::sync::atomic::{AtomicU64, Ordering};
static RNG_STATE_GLOBAL: AtomicU64 = AtomicU64::new(42);
pub fn seed_global(seed: u64) {
RNG_STATE_GLOBAL.store(seed, Ordering::Relaxed);
}
#[cfg(feature = "ctor")]
#[used]
#[cfg_attr(
any(target_os = "linux", target_os = "android", target_os = "freebsd"),
link_section = ".init_array"
)]
#[cfg_attr(target_os = "openbsd", link_section = ".ctors")]
#[cfg_attr(
any(target_os = "macos", target_os = "ios"),
link_section = "__DATA,__mod_init_func"
)]
#[cfg_attr(windows, link_section = ".CRT$XCU")]
static INITIALIZE_RAND_IN_CTOR: extern "C" fn() = {
#[cfg_attr(
any(target_os = "linux", target_os = "android"),
link_section = ".text.startup"
)]
extern "C" fn ctor() {
seed_global(entropy::entropy_from_system());
}
ctor
};