php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
php_random.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Rasmus Lerdorf <rasmus@php.net> |
14 | Zeev Suraski <zeev@php.net> |
15 | Sascha Schumann <sascha@schumann.cx> |
16 | Pedro Melo <melo@ip.pt> |
17 | Sterling Hughes <sterling@php.net> |
18 | Sammy Kaye Powers <me@sammyk.me> |
19 | Go Kudo <zeriyoshi@php.net> |
20 | |
21 | Based on code from: Richard J. Wagner <rjwagner@writeme.com> |
22 | Makoto Matsumoto <matumoto@math.keio.ac.jp> |
23 | Takuji Nishimura |
24 | Shawn Cokus <Cokus@math.washington.edu> |
25 | David Blackman |
26 | Sebastiano Vigna <vigna@acm.org> |
27 | Melissa O'Neill <oneill@pcg-random.org> |
28 +----------------------------------------------------------------------+
29*/
30
31#ifndef PHP_RANDOM_H
32# define PHP_RANDOM_H
33
34# include "php.h"
35# include "php_random_csprng.h"
36# include "php_random_uint128.h"
37
38PHPAPI double php_combined_lcg(void);
39
41
44
45static inline zend_long GENERATE_SEED(void)
46{
48}
49
50# define PHP_MT_RAND_MAX ((zend_long) (0x7FFFFFFF)) /* (1<<31) - 1 */
51
56
57#define PHP_RANDOM_RANGE_ATTEMPTS (50)
58
59PHPAPI void php_mt_srand(uint32_t seed);
60PHPAPI uint32_t php_mt_rand(void);
63
69
73
77
82
83typedef struct _php_random_result {
84 uint64_t result;
85 size_t size;
87
95
100
105
111
116
122
125
129
134
136
138
139static inline php_random_engine *php_random_engine_from_obj(zend_object *object) {
140 return (php_random_engine *)((char *)(object) - XtOffsetOf(php_random_engine, std));
141}
142
143static inline php_random_randomizer *php_random_randomizer_from_obj(zend_object *object) {
144 return (php_random_randomizer *)((char *)(object) - XtOffsetOf(php_random_randomizer, std));
145}
146
147# define Z_RANDOM_ENGINE_P(zval) php_random_engine_from_obj(Z_OBJ_P(zval))
148
149# define Z_RANDOM_RANDOMIZER_P(zval) php_random_randomizer_from_obj(Z_OBJ_P(zval));
150
151PHPAPI void *php_random_status_alloc(const php_random_algo *algo, const bool persistent);
152PHPAPI void *php_random_status_copy(const php_random_algo *algo, void *old_status, void *new_status);
153PHPAPI void php_random_status_free(void *status, const bool persistent);
158PHPAPI uint64_t php_random_range64(php_random_algo_with_state engine, uint64_t umax);
162
163static inline php_random_algo_with_state php_random_default_engine(void)
164{
168 return raws;
169}
170
171PHPAPI zend_string *php_random_bin2hex_le(const void *ptr, const size_t len);
172PHPAPI bool php_random_hex2bin_le(zend_string *hexstr, void *dest);
173
176
179
181PHPAPI void php_random_xoshiro256starstar_seed256(php_random_status_state_xoshiro256starstar *state, uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3);
184
189
191# define phpext_random_ptr &random_module_entry
192
193PHP_MINIT_FUNCTION(random);
195PHP_RINIT_FUNCTION(random);
196
201 int32_t combined_lcg[2];
204
206
207# define RANDOM_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(random, v)
208
209#endif /* PHP_RANDOM_H */
size_t len
Definition apprentice.c:174
char s[4]
Definition cdf.c:77
DNS_STATUS status
Definition dns_win32.c:49
PHPAPI const php_random_algo php_random_algo_mt19937
PHPAPI const php_random_algo php_random_algo_pcgoneseq128xslrr64
PHPAPI const php_random_algo php_random_algo_secure
PHPAPI const php_random_algo php_random_algo_user
Definition engine_user.c:76
PHPAPI const php_random_algo php_random_algo_xoshiro256starstar
#define max(a, b)
Definition exif.c:60
void * ptr
Definition ffi.c:3814
ffi persistent
Definition ffi.c:3633
#define PHP_MSHUTDOWN_FUNCTION
Definition php.h:401
#define PHP_MINIT_FUNCTION
Definition php.h:400
#define PHP_RINIT_FUNCTION
Definition php.h:402
#define PHPAPI
Definition php.h:71
zend_stack handlers
Definition php_output.h:139
#define min(a, b)
PHPAPI zend_class_entry * random_ce_Random_Engine
PHPAPI zend_string * php_random_bin2hex_le(const void *ptr, const size_t len)
Definition random.c:332
PHPAPI bool php_random_hex2bin_le(zend_string *hexstr, void *dest)
Definition random.c:358
struct _php_random_status_state_pcgoneseq128xslrr64 php_random_status_state_pcgoneseq128xslrr64
PHPAPI zend_long php_mt_rand_common(zend_long min, zend_long max)
Definition random.c:463
PHPAPI zend_object * php_random_engine_common_clone_object(zend_object *object)
Definition random.c:277
PHPAPI php_random_engine * php_random_engine_common_init(zend_class_entry *ce, zend_object_handlers *handlers, const php_random_algo *algo)
Definition random.c:253
PHPAPI zend_class_entry * random_ce_Random_RandomError
PHPAPI zend_long php_mt_rand_range(zend_long min, zend_long max)
Definition random.c:455
PHPAPI zend_class_entry * random_ce_Random_Engine_PcgOneseq128XslRr64
PHPAPI zend_class_entry * random_ce_Random_Randomizer
PHPAPI void php_random_pcgoneseq128xslrr64_seed128(php_random_status_state_pcgoneseq128xslrr64 *s, php_random_uint128_t seed)
PHPAPI void * php_random_status_alloc(const php_random_algo *algo, const bool persistent)
Definition random.c:238
PHPAPI double php_random_gammasection_closed_closed(php_random_algo_with_state engine, double min, double max)
PHPAPI void php_random_xoshiro256starstar_seed64(php_random_status_state_xoshiro256starstar *state, uint64_t seed)
bool mt19937_seeded
Definition php_random.h:199
PHPAPI void php_mt_srand(uint32_t seed)
Definition random.c:441
php_random_fallback_seed_state fallback_seed_state
Definition php_random.h:200
struct _php_random_algo_with_state php_random_algo_with_state
PHPAPI zend_class_entry * random_ce_Random_Engine_Mt19937
PHPAPI void php_random_xoshiro256starstar_jump_long(php_random_status_state_xoshiro256starstar *state)
PHPAPI uint64_t php_random_generate_fallback_seed(void)
Definition random.c:716
PHPAPI double php_random_gammasection_open_closed(php_random_algo_with_state engine, double min, double max)
php_random_status_state_mt19937 mt19937
Definition php_random.h:202
PHPAPI zend_class_entry * random_ce_Random_RandomException
int32_t combined_lcg[2]
Definition php_random.h:201
PHPAPI uint64_t php_random_generate_fallback_seed_ex(php_random_fallback_seed_state *state)
Definition random.c:644
PHPAPI void php_random_engine_common_free_object(zend_object *object)
Definition random.c:269
PHPAPI const php_random_algo * php_random_default_algo(void)
Definition random.c:306
struct _php_random_status_state_mt19937 php_random_status_state_mt19937
PHPAPI void php_random_xoshiro256starstar_jump(php_random_status_state_xoshiro256starstar *state)
PHPAPI zend_class_entry * random_ce_Random_CryptoSafeEngine
PHPAPI zend_class_entry * random_ce_Random_IntervalBoundary
PHPAPI void * php_random_status_copy(const php_random_algo *algo, void *old_status, void *new_status)
Definition random.c:243
PHPAPI zend_class_entry * random_ce_Random_Engine_Xoshiro256StarStar
struct _php_random_fallback_seed_state php_random_fallback_seed_state
Definition php_random.h:40
PHPAPI void php_random_mt19937_seed32(php_random_status_state_mt19937 *state, uint32_t seed)
struct _php_random_status_state_user php_random_status_state_user
struct _php_random_engine php_random_engine
PHPAPI zend_class_entry * random_ce_Random_Engine_Secure
PHPAPI uint32_t php_mt_rand(void)
Definition random.c:448
PHPAPI void php_random_xoshiro256starstar_seed256(php_random_status_state_xoshiro256starstar *state, uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3)
PHPAPI double php_random_gammasection_open_open(php_random_algo_with_state engine, double min, double max)
PHPAPI zend_long php_random_range(php_random_algo_with_state engine, zend_long min, zend_long max)
Definition random.c:293
PHPAPI double php_combined_lcg(void)
Definition random.c:397
php_random_mt19937_mode
Definition php_random.h:52
@ MT_RAND_PHP
Definition php_random.h:54
@ MT_RAND_MT19937
Definition php_random.h:53
struct _php_random_algo php_random_algo
PHPAPI uint64_t php_random_range64(php_random_algo_with_state engine, uint64_t umax)
Definition random.c:139
bool combined_lcg_seeded
Definition php_random.h:198
struct _php_random_status_state_xoshiro256starstar php_random_status_state_xoshiro256starstar
PHPAPI void php_random_pcgoneseq128xslrr64_advance(php_random_status_state_pcgoneseq128xslrr64 *state, uint64_t advance)
PHPAPI void php_random_mt19937_seed_default(php_random_status_state_mt19937 *state)
PHPAPI double php_random_gammasection_closed_open(php_random_algo_with_state engine, double min, double max)
struct _php_random_randomizer php_random_randomizer
PHPAPI void * php_random_default_status(void)
Definition random.c:313
PHPAPI zend_class_entry * random_ce_Random_BrokenRandomEngineError
zend_module_entry random_module_entry
Definition random.c:816
PHPAPI void php_random_status_free(void *status, const bool persistent)
Definition random.c:248
struct _php_random_result php_random_result
PHPAPI uint32_t php_random_range32(php_random_algo_with_state engine, uint32_t umax)
struct _php_random_uint128_t php_random_uint128_t
zend_constant * data
const php_random_algo * algo
Definition php_random.h:97
bool(* unserialize)(void *state, HashTable *data)
Definition php_random.h:93
php_random_result(* generate)(void *state)
Definition php_random.h:90
zend_long(* range)(void *state, zend_long min, zend_long max)
Definition php_random.h:91
const size_t state_size
Definition php_random.h:89
bool(* serialize)(void *state, HashTable *data)
Definition php_random.h:92
zend_object std
Definition php_random.h:114
php_random_algo_with_state engine
Definition php_random.h:113
php_random_algo_with_state engine
Definition php_random.h:118
enum php_random_mt19937_mode mode
Definition php_random.h:66
zend_function * generate_method
Definition php_random.h:80
#define ZEND_END_MODULE_GLOBALS(module_name)
Definition zend_API.h:248
#define ZEND_EXTERN_MODULE_GLOBALS(module_name)
Definition zend_API.h:270
#define ZEND_BEGIN_MODULE_GLOBALS(module_name)
Definition zend_API.h:246
union _zend_function zend_function
int32_t zend_long
Definition zend_long.h:42
struct _zend_string zend_string
struct _zend_module_entry zend_module_entry
#define XtOffsetOf(s_type, field)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
struct _zend_array HashTable
Definition zend_types.h:386
struct _zend_object_handlers zend_object_handlers
Definition zend_types.h:88