diff --git a/ext/colopl_bc_php70.c b/ext/colopl_bc_php70.c index 928722d..937ddd1 100644 --- a/ext/colopl_bc_php70.c +++ b/ext/colopl_bc_php70.c @@ -142,6 +142,15 @@ PHP_FUNCTION(Colopl_ColoplBc_Php70_getrandmax) /* mt_rand.c */ +#define N COLOPL_BC_MT_N /* length of state vector */ +#define M (397) /* a period parameter */ +#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */ +#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */ +#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */ +#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */ + +#define twist(m,u,v) (m ^ (mixBits(u,v)>>1) ^ ((uint32_t)(-(uint32_t)(loBit(u))) & 0x9908b0dfU)) + static inline void mt_initialize(uint32_t seed, uint32_t *state) { register uint32_t *s = state; diff --git a/ext/php_colopl_bc.h b/ext/php_colopl_bc.h index 927d406..dabda2f 100644 --- a/ext/php_colopl_bc.h +++ b/ext/php_colopl_bc.h @@ -48,7 +48,7 @@ ZEND_BEGIN_MODULE_GLOBALS(colopl_bc) bool rand_is_seeded; bool mt_rand_is_seeded; uint32_t rand_seed; - uint32_t mt_state[N+1]; + uint32_t mt_state[COLOPL_BC_MT_N+1]; uint32_t *mt_next; int mt_left; int gnurandom_r[344]; diff --git a/ext/php_colopl_bc_php70.h b/ext/php_colopl_bc_php70.h index 08c493e..56a70e5 100644 --- a/ext/php_colopl_bc_php70.h +++ b/ext/php_colopl_bc_php70.h @@ -113,14 +113,7 @@ PHPAPI zend_long php_colopl_bc_rand(void); #define PHP_COLOPL_BC_MT_RAND_MAX ((zend_long) (0x7FFFFFFF)) /* (1<<31) - 1 */ -#define N (624) /* length of state vector */ -#define M (397) /* a period parameter */ -#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */ -#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */ -#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */ -#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */ - -#define twist(m,u,v) (m ^ (mixBits(u,v)>>1) ^ ((uint32_t)(-(uint32_t)(loBit(u))) & 0x9908b0dfU)) +#define COLOPL_BC_MT_N (624) PHPAPI void php_colopl_bc_mt_srand(uint32_t seed); PHPAPI uint32_t php_colopl_bc_mt_rand(void);