-
Notifications
You must be signed in to change notification settings - Fork 802
/
Copy pathrandom.php
268 lines (217 loc) · 7.42 KB
/
random.php
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
namespace {
use JetBrains\PhpStorm\Deprecated as Deprecated;
use JetBrains\PhpStorm\Internal\LanguageLevelTypeAware;
use JetBrains\PhpStorm\Internal\PhpStormStubsElementAvailable;
use JetBrains\PhpStorm\Pure;
/**
* Combined linear congruential generator
* @link https://php.net/manual/en/function.lcg-value.php
* @return float A pseudo random float value in the range of (0, 1)
*/
#[Deprecated("The function is deprecated", since: "8.4")]
function lcg_value(): float {}
/**
* Seeds the Mersenne Twister Random Number Generator
* @link https://php.net/manual/en/function.mt-srand.php
* @param int|null $seed <p>
* An optional seed value
* </p>
* @param int $mode [optional] <p>
* Use one of the following constants to specify the implementation of the algorithm to use.
* </p>
* @return void
*/
function mt_srand(
#[LanguageLevelTypeAware(['8.3' => 'int|null'], default: 'int')] $seed = null,
#[PhpStormStubsElementAvailable(from: '7.1')] int $mode = MT_RAND_MT19937
): void {}
/**
* Seed the random number generator
* <p><strong>Note</strong>: As of PHP 7.1.0, {@see srand()} has been made
* an alias of {@see mt_srand()}.
* </p>
* @link https://php.net/manual/en/function.srand.php
* @param int|null $seed <p>
* Optional seed value
* </p>
* @param int $mode [optional] <p>
* Use one of the following constants to specify the implementation of the algorithm to use.
* </p>
* @return void
*/
function srand(
#[LanguageLevelTypeAware(['8.3' => 'int|null'], default: 'int')] $seed = null,
#[PhpStormStubsElementAvailable(from: '7.1')] int $mode = MT_RAND_MT19937
): void {}
/**
* Generate a random integer
* @link https://php.net/manual/en/function.rand.php
* @param int $min [optional]
* @param int $max [optional]
* @return int A pseudo random value between min
* (or 0) and max (or getrandmax, inclusive).
*/
function rand(int $min, int $max): int {}
/**
* Generate a random value via the Mersenne Twister Random Number Generator
* @link https://php.net/manual/en/function.mt-rand.php
* @param int $min [optional] <p>
* Optional lowest value to be returned (default: 0)
* </p>
* @param int $max [optional] <p>
* Optional highest value to be returned (default: mt_getrandmax())
* </p>
* @return int A random integer value between min (or 0)
* and max (or mt_getrandmax, inclusive)
*/
function mt_rand(int $min, int $max): int {}
/**
* Show largest possible random value
* @link https://php.net/manual/en/function.mt-getrandmax.php
* @return int the maximum random value returned by mt_rand
*/
#[Pure]
function mt_getrandmax(): int {}
/**
* Show largest possible random value
* @link https://php.net/manual/en/function.getrandmax.php
* @return int The largest possible random value returned by rand
*/
#[Pure]
function getrandmax(): int {}
/**
* Generates cryptographically secure pseudo-random bytes
* @link https://php.net/manual/en/function.random-bytes.php
* @param int $length The length of the random string that should be returned in bytes.
* @return string Returns a string containing the requested number of cryptographically secure random bytes.
* @since 7.0
* @throws Random\RandomException if an appropriate source of randomness cannot be found.
*/
function random_bytes(int $length): string {}
/**
* Generates cryptographically secure pseudo-random integers
* @link https://php.net/manual/en/function.random-int.php
* @param int $min The lowest value to be returned, which must be PHP_INT_MIN or higher.
* @param int $max The highest value to be returned, which must be less than or equal to PHP_INT_MAX.
* @return int Returns a cryptographically secure random integer in the range min to max, inclusive.
* @since 7.0
* @throws Random\RandomException if an appropriate source of randomness cannot be found.
*/
function random_int(int $min, int $max): int {}
}
namespace Random\Engine
{
use const MT_RAND_MT19937;
/**
* @since 8.2
*/
final class Mt19937 implements \Random\Engine
{
public function __construct(int|null $seed = null, int $mode = MT_RAND_MT19937) {}
public function generate(): string {}
public function __serialize(): array {}
public function __unserialize(array $data): void {}
public function __debugInfo(): array {}
}
/**
* @since 8.2
*/
final class PcgOneseq128XslRr64 implements \Random\Engine
{
public function __construct(string|int|null $seed = null) {}
public function generate(): string {}
public function jump(int $advance): void {}
public function __serialize(): array {}
public function __unserialize(array $data): void {}
public function __debugInfo(): array {}
}
/**
* @since 8.2
*/
final class Xoshiro256StarStar implements \Random\Engine
{
public function __construct(string|int|null $seed = null) {}
public function generate(): string {}
public function jump(): void {}
public function jumpLong(): void {}
public function __serialize(): array {}
public function __unserialize(array $data): void {}
public function __debugInfo(): array {}
}
/**
* @since 8.2
*/
final class Secure implements \Random\CryptoSafeEngine
{
public function generate(): string {}
}
}
namespace Random
{
use Error;
use Exception;
/**
* @since 8.2
*/
interface Engine
{
public function generate(): string;
}
/**
* @since 8.2
*/
interface CryptoSafeEngine extends Engine {}
/**
* @since 8.2
*/
final class Randomizer
{
public readonly Engine $engine;
public function __construct(?Engine $engine = null) {}
public function nextInt(): int {}
public function getInt(int $min, int $max): int {}
public function getBytes(int $length): string {}
public function shuffleArray(array $array): array {}
public function shuffleBytes(string $bytes): string {}
public function pickArrayKeys(array $array, int $num): array {}
public function __serialize(): array {}
public function __unserialize(array $data): void {}
/**
* @since 8.3
*/
public function nextFloat(): float {}
/**
* @since 8.3
*/
public function getFloat(float $min, float $max, IntervalBoundary $boundary = IntervalBoundary::ClosedOpen): float {}
/**
* @since 8.3
*/
public function getBytesFromString(string $string, int $length): string {}
}
/**
* @since 8.2
*/
class RandomError extends Error {}
/**
* @since 8.2
*/
class BrokenRandomEngineError extends RandomError {}
/**
* @since 8.2
*/
class RandomException extends Exception {}
/**
* @since 8.3
*/
enum IntervalBoundary implements \UnitEnum
{
public string $name;
case ClosedOpen;
case ClosedClosed;
case OpenClosed;
case OpenOpen;
public static function cases(): array {}
}
}