1#[cfg(any(feature = "v4", feature = "v7"))]
2pub(crate) fn u128() -> u128 {
3 #[cfg(not(feature = "fast-rng"))]
4 {
5 let mut bytes = [0u8; 16];
6
7 getrandom::getrandom(&mut bytes).unwrap_or_else(|err| {
8 panic!("could not retrieve random bytes for uuid: {}", err)
10 });
11
12 u128::from_ne_bytes(bytes)
13 }
14
15 #[cfg(feature = "fast-rng")]
16 {
17 rand::random()
18 }
19}
20
21#[cfg(any(feature = "v1", feature = "v6"))]
22pub(crate) fn u16() -> u16 {
23 #[cfg(not(feature = "fast-rng"))]
24 {
25 let mut bytes = [0u8; 2];
26
27 getrandom::getrandom(&mut bytes).unwrap_or_else(|err| {
28 panic!("could not retrieve random bytes for uuid: {}", err)
30 });
31
32 u16::from_ne_bytes(bytes)
33 }
34
35 #[cfg(feature = "fast-rng")]
36 {
37 rand::random()
38 }
39}
40
41#[cfg(feature = "v7")]
42pub(crate) fn u64() -> u64 {
43 #[cfg(not(feature = "fast-rng"))]
44 {
45 let mut bytes = [0u8; 8];
46
47 getrandom::getrandom(&mut bytes).unwrap_or_else(|err| {
48 panic!("could not retrieve random bytes for uuid: {}", err)
50 });
51
52 u64::from_ne_bytes(bytes)
53 }
54
55 #[cfg(feature = "fast-rng")]
56 {
57 rand::random()
58 }
59}