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
102
103
104
105
106
//! Math utilities for random number generation and array operations
//!
//! This module provides mathematical utility functions including random number generation
//! and array manipulation functions.
use ;
use Error;
/// Errors that can occur during math operations
/// Generate a random integer in the range [start, end)
///
/// # Arguments
///
/// * `start` - Starting value (inclusive)
/// * `end` - Ending value (exclusive)
///
/// # Examples
///
/// ```rust
/// use mudssky_utils::math::random_int;
///
/// let num = random_int(0, 100).unwrap();
/// assert!(num >= 0 && num < 100);
///
/// let num = random_int(10, 20).unwrap();
/// assert!(num >= 10 && num < 20);
/// ```
///
/// # Errors
///
/// Returns `MathError::InvalidArgument` if start >= end
/// Generate a random integer in the range [0, max)
///
/// # Arguments
///
/// * `max` - Maximum value (exclusive)
///
/// # Examples
///
/// ```rust
/// use mudssky_utils::math::random_int_max;
///
/// let num = random_int_max(100).unwrap();
/// assert!(num >= 0 && num < 100);
/// ```
///
/// # Errors
///
/// Returns `MathError::InvalidArgument` if max <= 0
/// Get a random item from an array
///
/// # Arguments
///
/// * `arr` - The array to select from
///
/// # Examples
///
/// ```rust
/// use mudssky_utils::math::get_random_item_from_array;
///
/// let arr = vec![1, 2, 3, 4, 5];
/// let item = get_random_item_from_array(&arr).unwrap();
/// assert!(arr.contains(&item));
/// ```
///
/// # Errors
///
/// Returns `MathError::InvalidArgument` if the array is empty