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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use crate::Euui;
use rand::random;
impl Euui {
/// Generates a new random Euui.
///
/// Each component of the Euui is generated using the `rand` crate's `random` function.
///
/// ## Example
///
/// ```rust
/// use euui::Euui;
///
/// #[cfg(feature = "random")]
/// fn test_random() {
/// let euui = Euui::random();
/// println!("{}", euui);
/// }
/// ```
pub fn random() -> Self {
Self([random(), random(), random(), random()])
}
/// Generates a new random Euui with the first `u128` component provided
/// and the remaining three components generated randomly.
///
/// ## Arguments
///
/// * `first` - The first `u128` value to initialize the Euui.
///
/// ## Returns
///
/// A new `Euui` instance where the first `u128` value is set to the provided value,
/// and the other three components are randomly generated.
///
/// ## Example
///
/// ```rust
/// use euui::Euui;
///
/// #[cfg(feature = "random")]
/// fn test_random() {
/// let first = 0x1234567890abcdef1234567890abcdef;
/// let euui = Euui::random_from_first(first);
///
/// println!("{:?}", euui);
/// assert_eq!(euui.to_be_guids().first().unwrap(), &first);
/// }
/// ```
pub fn random_from_first(first: u128) -> Self {
Self([first, random(), random(), random()])
}
/// Generates a new random Euui with the second `u128` component provided
/// and the remaining three components generated randomly.
///
/// See [Self::random_from_first].
pub fn random_from_second(second: u128) -> Self {
Self([random(), second, random(), random()])
}
/// Generates a new random Euui with the third `u128` component provided
/// and the remaining three components generated randomly.
///
/// See [Self::random_from_first].
pub fn random_from_third(third: u128) -> Self {
Self([random(), random(), third, random()])
}
/// Generates a new random Euui with the fourth `u128` component provided
/// and the remaining three components generated randomly.
///
/// See [Self::random_from_first].
pub fn random_from_fourth(fourth: u128) -> Self {
Self([random(), random(), random(), fourth])
}
/// Generates a new `Euui` with a randomly generated first component,
/// leaving the remaining components unchanged.
pub fn regenerate_first(&self) -> Self {
Self([random(), self.0[1], self.0[2], self.0[3]])
}
/// Generates a new `Euui` with a randomly generated second component,
/// leaving the remaining components unchanged.
pub fn regenerate_second(&self) -> Self {
Self([self.0[0], random(), self.0[2], self.0[3]])
}
/// Generates a new `Euui` with a randomly generated third component,
/// leaving the remaining components unchanged.
pub fn regenerate_third(&self) -> Self {
Self([self.0[0], self.0[1], random(), self.0[3]])
}
/// Generates a new `Euui` with a randomly generated fourth component,
/// leaving the remaining components unchanged.
pub fn regenerate_fourth(&self) -> Self {
Self([self.0[0], self.0[1], self.0[2], random()])
}
}