1use crate::docs::entry::{FnEntry, StdEntry};
2
3pub static RANDOM: StdEntry = StdEntry {
4 name: "random",
5 description: "functions for random number and value generation",
6 functions: FUNCTIONS,
7 since: None,
8 unstable: false,
9};
10
11static FUNCTIONS: &[&FnEntry] = &[
12 &RAND_INT,
13 &RAND_INT_RANGE,
14 &RAND_FLOAT,
15 &RAND_FLOAT_RANGE,
16 &RAND_BOOL,
17 &RAND_BOOL_WEIGHTED,
18 &RAND_DICE,
19 &RAND_DICES,
20 &RAND_RANGE,
21 &RAND_RANGE_STEP,
22 &RAND_CHOICE,
23 &RAND_CHOICES,
24 &RAND_SAMPLE,
25 &RAND_SHUFFLE,
26 &RAND_BYTE,
27 &RAND_BYTES,
28 &RAND_CHAR,
29 &RAND_STRING,
30];
31
32static RAND_INT: FnEntry = FnEntry {
33 signature: "rand_int()",
34 description: "returns a random int across the full int range",
35 example: "get std::random::rand_int\n\nrand_int() // 4650267523947147985",
36 expected_output: None,
37 returns: "",
38 errors: None,
39 see_also: &[],
40 since: None,
41};
42
43static RAND_INT_RANGE: FnEntry = FnEntry {
44 signature: "rand_int_range(min, max)",
45 description: "returns a random int between min and max (inclusive)",
46 example: "get std::random::rand_int_range\n\nrand_int_range(1, 6) // 4",
47 expected_output: None,
48 returns: "",
49 errors: None,
50 see_also: &[],
51 since: None,
52};
53
54static RAND_FLOAT: FnEntry = FnEntry {
55 signature: "rand_float()",
56 description: "returns a random float between 0.0 and 1.0",
57 example: "get std::random::rand_float\n\nrand_float() // 0.3528",
58 expected_output: None,
59 returns: "",
60 errors: None,
61 see_also: &[],
62 since: None,
63};
64
65static RAND_FLOAT_RANGE: FnEntry = FnEntry {
66 signature: "rand_float_range(min, max)",
67 description: "returns a random float between min and max",
68 example: "get std::random::rand_float_range\n\nrand_float_range(1.0, 2.0) // 1.5124",
69 expected_output: None,
70 returns: "",
71 errors: None,
72 see_also: &[],
73 since: None,
74};
75
76static RAND_BOOL: FnEntry = FnEntry {
77 signature: "rand_bool()",
78 description: "returns a random bool, using an internally randomized probability",
79 example: "get std::random::rand_bool\n\nrand_bool() // true",
80 expected_output: None,
81 returns: "",
82 errors: None,
83 see_also: &[],
84 since: None,
85};
86
87static RAND_BOOL_WEIGHTED: FnEntry = FnEntry {
88 signature: "rand_bool_weighted(probability)",
89 description: "returns a random bool that is true with the given probability (0.0 to 1.0) values smaller than 0.0 will be 0.0 and values bigger than 1.0 will be 1.0",
90 example: "get std::random::rand_bool_weighted\n\nrand_bool_weighted(0.8) // true",
91 expected_output: None,
92 returns: "",
93 errors: None,
94 see_also: &[],
95 since: None,
96};
97
98static RAND_DICE: FnEntry = FnEntry {
99 signature: "rand_dice(sides)",
100 description: "rolls a single die with the given number of sides and returns the result",
101 example: "get std::random::rand_dice\n\nrand_dice(6) // 5",
102 expected_output: None,
103 returns: "",
104 errors: None,
105 see_also: &[],
106 since: None,
107};
108
109static RAND_DICES: FnEntry = FnEntry {
110 signature: "rand_dices(count, sides)",
111 description: "rolls count dice with the given number of sides and returns the individual results as an array",
112 example: "get std::random::rand_dices\n\nrand_dices(3, 6) // [4, 1, 6]",
113 expected_output: None,
114 returns: "",
115 errors: None,
116 see_also: &[],
117 since: None,
118};
119
120static RAND_RANGE: FnEntry = FnEntry {
121 signature: "rand_range(stop)",
122 description: "returns a random int from 0 to stop (exclusive), stop must be greater than zero",
123 example: "get std::random::rand_range\n\nrand_range(10) // 7",
124 expected_output: None,
125 returns: "",
126 errors: None,
127 see_also: &[],
128 since: None,
129};
130
131static RAND_RANGE_STEP: FnEntry = FnEntry {
132 signature: "rand_range_step(start, end, step)",
133 description: "returns a random int from start to end, aligned to step; reaches end only if step divides (end - start) evenly, otherwise caps at the highest reachable multiple below end",
134 example: "get std::random::rand_range_step\n\nrand_range_step(0, 9, 2) // 8 (max possible, since 9 isn't reachable)",
135 expected_output: None,
136 returns: "",
137 errors: None,
138 see_also: &[],
139 since: None,
140};
141
142static RAND_CHOICE: FnEntry = FnEntry {
143 signature: "rand_choice(arr)",
144 description: "returns a random element from the array",
145 example: "get std::random::rand_choice\n\nrand_choice([1, 2, 3]) // 1",
146 expected_output: None,
147 returns: "",
148 errors: None,
149 see_also: &[],
150 since: None,
151};
152
153static RAND_CHOICES: FnEntry = FnEntry {
154 signature: "rand_choices(arr, count)",
155 description: "returns an array of count random elements from arr, with replacement",
156 example: "get std::random::rand_choices\n\nrand_choices([1, 2, 3], 5) // [1, 1, 3, 1, 1]",
157 expected_output: None,
158 returns: "",
159 errors: None,
160 see_also: &[],
161 since: None,
162};
163
164static RAND_SAMPLE: FnEntry = FnEntry {
165 signature: "rand_sample(arr, count)",
166 description: "returns an array of count random elements from arr, without replacement (count must not exceed arr's length)",
167 example: "get std::random::rand_sample\n\nrand_sample([1, 2, 3, 4], 2) // [4, 2]",
168 expected_output: None,
169 returns: "",
170 errors: None,
171 see_also: &[],
172 since: None,
173};
174
175static RAND_SHUFFLE: FnEntry = FnEntry {
176 signature: "rand_shuffle(arr)",
177 description: "returns the array with its elements in random order",
178 example: "get std::random::rand_shuffle\n\nrand_shuffle([1, 2, 3, 4, 5]) // [3, 5, 1, 4, 2]",
179 expected_output: None,
180 returns: "",
181 errors: None,
182 see_also: &[],
183 since: None,
184};
185
186static RAND_BYTE: FnEntry = FnEntry {
187 signature: "rand_byte()",
188 description: "returns a random byte (0 to 255)",
189 example: "get std::random::rand_byte\n\nrand_byte() // 110",
190 expected_output: None,
191 returns: "",
192 errors: None,
193 see_also: &[],
194 since: None,
195};
196
197static RAND_BYTES: FnEntry = FnEntry {
198 signature: "rand_bytes(count)",
199 description: "returns an array of count random bytes",
200 example: "get std::random::rand_bytes\n\nrand_bytes(4) // [226, 232, 81, 178]",
201 expected_output: None,
202 returns: "",
203 errors: None,
204 see_also: &[],
205 since: None,
206};
207
208static RAND_CHAR: FnEntry = FnEntry {
209 signature: "rand_char()",
210 description: "returns a random printable ascii character (32 to 126)",
211 example: "get std::random::rand_char\n\nrand_char() // 'c'",
212 expected_output: None,
213 returns: "",
214 errors: None,
215 see_also: &[],
216 since: None,
217};
218
219static RAND_STRING: FnEntry = FnEntry {
220 signature: "rand_string(count)",
221 description: "returns a random printable ascii string of the given length",
222 example: "get std::random::rand_string\n\nrand_string(8) // \"oNU7'=^:\"",
223 expected_output: None,
224 returns: "",
225 errors: None,
226 see_also: &[],
227 since: None,
228};