Back to index

php5  5.3.10
Defines | Functions
php_rand.h File Reference
#include <stdlib.h>
#include "basic_functions.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define RAND_MAX   (1<<15)
#define PHP_RAND_MAX   RAND_MAX
#define RAND_RANGE(__n, __min, __max, __tmax)   (__n) = (__min) + (long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0)))
#define PHP_MT_RAND_MAX   ((long) (0x7FFFFFFF)) /* (1<<31) - 1 */
#define GENERATE_SEED()   (((long) (time(0) * getpid())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C))))

Functions

PHPAPI void php_srand (long seed TSRMLS_DC)
PHPAPI long php_rand (TSRMLS_D)
PHPAPI void php_mt_srand (php_uint32 seed TSRMLS_DC)
PHPAPI php_uint32 php_mt_rand (TSRMLS_D)

Define Documentation

#define GENERATE_SEED ( )    (((long) (time(0) * getpid())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C))))

Definition at line 52 of file php_rand.h.

#define PHP_MT_RAND_MAX   ((long) (0x7FFFFFFF)) /* (1<<31) - 1 */

Definition at line 47 of file php_rand.h.

#define PHP_RAND_MAX   RAND_MAX

Definition at line 40 of file php_rand.h.

#define RAND_MAX   (1<<15)

Definition at line 33 of file php_rand.h.

#define RAND_RANGE (   __n,
  __min,
  __max,
  __tmax 
)    (__n) = (__min) + (long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0)))

Definition at line 43 of file php_rand.h.


Function Documentation

PHPAPI php_uint32 php_mt_rand ( TSRMLS_D  )

Definition at line 209 of file rand.c.

{
       /* Pull a 32-bit integer from the generator state
          Every other access function simply transforms the numbers extracted here */
       
       register php_uint32 s1;

       if (BG(left) == 0) {
              php_mt_reload(TSRMLS_C);
       }
       --BG(left);
              
       s1 = *BG(next)++;
       s1 ^= (s1 >> 11);
       s1 ^= (s1 <<  7) & 0x9d2c5680U;
       s1 ^= (s1 << 15) & 0xefc60000U;
       return ( s1 ^ (s1 >> 18) );
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI void php_mt_srand ( php_uint32 seed  TSRMLS_DC)

Definition at line 196 of file rand.c.

{
       /* Seed the generator with a simple uint32 */
       php_mt_initialize(seed, BG(state));
       php_mt_reload(TSRMLS_C);

       /* Seed only once */
       BG(mt_rand_is_seeded) = 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI long php_rand ( TSRMLS_D  )

Definition at line 63 of file rand.c.

{
       long ret;

       if (!BG(rand_is_seeded)) {
              php_srand(GENERATE_SEED() TSRMLS_CC);
       }

#ifdef ZTS
       ret = php_rand_r(&BG(rand_seed));
#else
# if defined(HAVE_RANDOM)
       ret = random();
# elif defined(HAVE_LRAND48)
       ret = lrand48();
# else
       ret = rand();
# endif
#endif

       return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI void php_srand ( long seed  TSRMLS_DC)

Definition at line 42 of file rand.c.

{
#ifdef ZTS
       BG(rand_seed) = (unsigned int) seed;
#else
# if defined(HAVE_SRANDOM)
       srandom((unsigned int) seed);
# elif defined(HAVE_SRAND48)
       srand48(seed);
# else
       srand((unsigned int) seed);
# endif
#endif

       /* Seed only once */
       BG(rand_is_seeded) = 1;
}

Here is the caller graph for this function: