Back to index

php5  5.3.10
Defines | Functions | Variables
lcg.c File Reference
#include "php.h"
#include "php_lcg.h"
#include <sys/time.h>

Go to the source code of this file.

Defines

#define MODMULT(a, b, c, m, s)   q = s/a;s=b*(s-a*q)-c*q;if(s<0)s+=m

Functions

static void lcg_seed (TSRMLS_D)
PHPAPI double php_combined_lcg (TSRMLS_D)
static void lcg_init_globals (php_lcg_globals *lcg_globals_p TSRMLS_DC)
 PHP_MINIT_FUNCTION (lcg)
 PHP_FUNCTION (lcg_value)

Variables

static php_lcg_globals lcg_globals

Define Documentation

#define MODMULT (   a,
  b,
  c,
  m,
 
)    q = s/a;s=b*(s-a*q)-c*q;if(s<0)s+=m

Definition at line 51 of file lcg.c.


Function Documentation

static void lcg_init_globals ( php_lcg_globals *lcg_globals_p  TSRMLS_DC) [static]

Definition at line 100 of file lcg.c.

{
       LCG(seeded) = 0;
}

Here is the caller graph for this function:

static void lcg_seed ( TSRMLS_D  ) [static]

Definition at line 76 of file lcg.c.

{
       struct timeval tv;

       if (gettimeofday(&tv, NULL) == 0) {
              LCG(s1) = tv.tv_sec ^ (tv.tv_usec<<11);
       } else {
              LCG(s1) = 1;
       }
#ifdef ZTS
       LCG(s2) = (long) tsrm_thread_id();
#else
       LCG(s2) = (long) getpid();
#endif

       /* Add entropy to s2 by calling gettimeofday() again */
       if (gettimeofday(&tv, NULL) == 0) {
              LCG(s2) ^= (tv.tv_usec<<11);
       }

       LCG(seeded) = 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 55 of file lcg.c.

{
       php_int32 q;
       php_int32 z;

       if (!LCG(seeded)) {
              lcg_seed(TSRMLS_C);
       }

       MODMULT(53668, 40014, 12211, 2147483563L, LCG(s1));
       MODMULT(52774, 40692, 3791, 2147483399L, LCG(s2));

       z = LCG(s1) - LCG(s2);
       if (z < 1) {
              z += 2147483562;
       }

       return z * 4.656613e-10;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_FUNCTION ( lcg_value  )

Definition at line 119 of file lcg.c.

Here is the call graph for this function:

PHP_MINIT_FUNCTION ( lcg  )

Definition at line 106 of file lcg.c.

{
#ifdef ZTS
       ts_allocate_id(&lcg_globals_id, sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL);
#else
       lcg_init_globals(&lcg_globals);
#endif
       return SUCCESS;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 37 of file lcg.c.