Ejemplo n.º 1
0
/*
 *	Generate some initially weak seeding values to allow
 *	to start the random32() engine.
 */
static int __init random32_init(void)
{

  /* dacashman change */
  struct rnd_state *state_cpy;


	int i;
	
	for_each_possible_cpu(i) {
		struct rnd_state *state = &per_cpu(net_rand_state,i);

#define LCG(x)	((x) * 69069)	/* super-duper LCG */
		state->s1 = __seed(LCG(i + jiffies), 1);
		state->s2 = __seed(LCG(state->s1), 7);
		state->s3 = __seed(LCG(state->s2), 15);

		/* "warm it up" */
		__random32(state);
		__random32(state);
		__random32(state);
		__random32(state);
		__random32(state);
		__random32(state);


		/* dacashman change */
		state_cpy = state;
	}

	/* dacashman change */
	printk(KERN_DEBUG "RANDOM - random32 init called.  Value: %x\t%x\t%x\n", state_cpy->s1, state_cpy->s2, state_cpy->s3);
	return 0;
}
Ejemplo n.º 2
0
static void
mrg_set (void *vstate, unsigned long int s)
{
  /* An entirely adhoc way of seeding! This does **not** come from
     L'Ecuyer et al */

  mrg_state_t *state = (mrg_state_t *) vstate;

  if (s == 0)
    s = 1;      /* default seed is 1 */

#define LCG(n) ((69069 * n) & 0xffffffffUL)
  s = LCG (s);
  state->x1 = s % m;
  s = LCG (s);
  state->x2 = s % m;
  s = LCG (s);
  state->x3 = s % m;
  s = LCG (s);
  state->x4 = s % m;
  s = LCG (s);
  state->x5 = s % m;

  /* "warm it up" with at least 5 calls to go through
     all the x values */

  mrg_get (state);
  mrg_get (state);
  mrg_get (state);
  mrg_get (state);
  mrg_get (state);
  mrg_get (state);

  return;
}
Ejemplo n.º 3
0
static void
taus2_set (void *vstate, unsigned long int s)
{
    taus_state_t *state = (taus_state_t *) vstate;

    if (s == 0)
        s = 1;      /* default seed is 1 */

#define LCG(n) ((69069 * n) & 0xffffffffUL)
    state->s1 = LCG (s);
    if (state->s1 < 2) state->s1 += 2UL;
    state->s2 = LCG (state->s1);
    if (state->s2 < 8) state->s2 += 8UL;
    state->s3 = LCG (state->s2);
    if (state->s3 < 16) state->s3 += 16UL;

    /* "warm it up" */
    taus_get (state);
    taus_get (state);
    taus_get (state);
    taus_get (state);
    taus_get (state);
    taus_get (state);
    return;
}
Ejemplo n.º 4
0
Archivo: rand.c Proyecto: DrGonzo65/fio
static void __init_rand(struct frand_state *state, unsigned int seed)
{
	int cranks = 6;

#define LCG(x, seed)  ((x) * 69069 ^ (seed))

	state->s1 = __seed(LCG((2^31) + (2^17) + (2^7), seed), 1);
	state->s2 = __seed(LCG(state->s1, seed), 7);
	state->s3 = __seed(LCG(state->s2, seed), 15);

	while (cranks--)
		__rand(state);
}
Ejemplo n.º 5
0
static void pnl_mrgk5_sseed (mrgk5_state *s, ulong seed)
{
  if ( seed == 0 )
    {
      s->x10= 231458761.;
      s->x11= 34125679.;
      s->x12= 45678213.;
      s->x13= 7438902.;
      s->x14= 957345.;

      s->x20= 57964412.;
      s->x21= 12365487.;
      s->x22= 77221456.;
      s->x23= 816403.;
      s->x24= 8488912.;
    }
  else
    {
      static const ulong M   = 4294949027UL;
      ulong n = seed;
      n = LCG(n);
      s->x10 = n % M;
      n = LCG(n);
      s->x11 = n % M;
      n = LCG(n);
      s->x12 = n % M;
      n = LCG(n);
      s->x13 = n % M;
      n = LCG(n);
      s->x14 = n % M;

      n = LCG(n);
      s->x20 = n % M;
      n = LCG(n);
      s->x21 = n % M;
      n = LCG(n);
      s->x22 = n % M;
      n = LCG(n);
      s->x23 = n % M;
      n = LCG(n);
      s->x24 = n % M;

      /*
       * We should run the generator a few times to warm it up, but it
       * requires to change the header of sseed functions to pas them rng
       * object and not only the states
       */
    }
}
Ejemplo n.º 6
0
Archivo: rand.c Proyecto: jeefke/fio
void init_rand(struct frand_state *state)
{
#define LCG(x)  ((x) * 69069)   /* super-duper LCG */

	state->s1 = __seed(LCG((2^31) + (2^17) + (2^7)), 1);
	state->s2 = __seed(LCG(state->s1), 7);
	state->s3 = __seed(LCG(state->s2), 15);

	__rand(state);
	__rand(state);
	__rand(state);
	__rand(state);
	__rand(state);
	__rand(state);
}
Ejemplo n.º 7
0
static void lcg_seed(TSRMLS_D) /* {{{ */
{
	struct timeval tv;

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

	LCG(seeded) = 1;
}
Ejemplo n.º 8
0
static void __net_srandom(struct nrnd_state *state, unsigned long s)
{
	if (s == 0)
		s = 1;      /* default seed is 1 */

#define LCG(n) (69069 * n)
	state->s1 = LCG(s);
	state->s2 = LCG(state->s1);
	state->s3 = LCG(state->s2);

	/* "warm it up" */
	__net_random(state);
	__net_random(state);
	__net_random(state);
	__net_random(state);
	__net_random(state);
	__net_random(state);
}
Ejemplo n.º 9
0
PHPAPI double php_combined_lcg(TSRMLS_D) /* {{{ */
{
	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;
}
Ejemplo n.º 10
0
void RNG_taus::set (unsigned long int s)
{
  if (s == 0)
    s = 1;      /* default seed is 1 */

  s1 = LCG (s);
  if (s1 < 2) s1 += 2UL;
    s2 = LCG (s1);
  if (s2 < 8) s2 += 8UL;
    s3 = LCG (s2);
  if (s3 < 16) s3 += 16UL;
    
  /* "warm it up" */
  get_UL ();
  get_UL ();
  get_UL ();
  get_UL ();
  get_UL ();
  get_UL ();
  return;
}
Ejemplo n.º 11
0
static void
cmrg_set (void *vstate, unsigned long int s)
{
    /* An entirely adhoc way of seeding! This does **not** come from
       L'Ecuyer et al */

    cmrg_state_t *state = (cmrg_state_t *) vstate;

    if (s == 0)
        s = 1;      /* default seed is 1 */

#define LCG(n) ((69069 * n) & 0xffffffffUL)
    s = LCG (s);
    state->x1 = s % m1;
    s = LCG (s);
    state->x2 = s % m1;
    s = LCG (s);
    state->x3 = s % m1;

    s = LCG (s);
    state->y1 = s % m2;
    s = LCG (s);
    state->y2 = s % m2;
    s = LCG (s);
    state->y3 = s % m2;

    /* "warm it up" */
    cmrg_get (state);
    cmrg_get (state);
    cmrg_get (state);
    cmrg_get (state);
    cmrg_get (state);
    cmrg_get (state);
    cmrg_get (state);
}
Ejemplo n.º 12
0
static int __init random32_init(void)
{
	int i;

	for_each_possible_cpu(i) {
		struct rnd_state *state = &per_cpu(net_rand_state,i);

#define LCG(x)	((x) * 69069)	
		state->s1 = __seed(LCG(i + jiffies), 1);
		state->s2 = __seed(LCG(state->s1), 7);
		state->s3 = __seed(LCG(state->s2), 15);

		
		prandom32(state);
		prandom32(state);
		prandom32(state);
		prandom32(state);
		prandom32(state);
		prandom32(state);
	}
	return 0;
}
Ejemplo n.º 13
0
/*
 *	Generate some initially weak seeding values to allow
 *	to start the random32() engine.
 */
static int __init random32_init(void)
{
	int i;

	for_each_possible_cpu(i) {
		struct rnd_state *state = &per_cpu(net_rand_state,i);

#define LCG(x)	((x) * 69069)	/* super-duper LCG */
		state->s1 = __seed(LCG(i + jiffies), 2);
		state->s2 = __seed(LCG(state->s1), 8);
		state->s3 = __seed(LCG(state->s2), 16);

		/* "warm it up" */
		prandom32(state);
		prandom32(state);
		prandom32(state);
		prandom32(state);
		prandom32(state);
		prandom32(state);
	}
	return 0;
}
Ejemplo n.º 14
0
static void
gfsr4_set (void *vstate, unsigned long int s)
{
  gfsr4_state_t *state = (gfsr4_state_t *) vstate;
  int i, j;
  /* Masks for turning on the diagonal bit and turning off the
     leftmost bits */
  unsigned long int msb = 0x80000000UL;
  unsigned long int mask = 0xffffffffUL;

  if (s == 0)
    s = 4357;	/* the default seed is 4357 */

  /* We use the congruence s_{n+1} = (69069*s_n) mod 2^32 to
     initialize the state. This works because ANSI-C unsigned long
     integer arithmetic is automatically modulo 2^32 (or a higher
     power of two), so we can safely ignore overflow. */

#define LCG(n) ((69069 * n) & 0xffffffffUL)

  /* Brian Gough suggests this to avoid low-order bit correlations */
  for (i = 0; i <= M; i++)
    {
      unsigned long t = 0 ;
      unsigned long bit = msb ;
      for (j = 0; j < 32; j++)
	{
	  s = LCG(s) ;
	  if (s & msb) 
	    t |= bit ;
	  bit >>= 1 ;
	}
      state->ra[i] = t ;
    }

  /* Perform the "orthogonalization" of the matrix */
  /* Based on the orthogonalization used in r250, as suggested initially
   * by Kirkpatrick and Stoll, and pointed out to me by Brian Gough
   */
  for (i=0; i<32; ++i) {
      int k=7+i*3;
      state->ra[k] &= mask;	/* Turn off bits left of the diagonal */
      state->ra[k] |= msb;	/* Turn on the diagonal bit           */
      mask >>= 1;
      msb >>= 1;
  }

  state->nd = i;
}
Ejemplo n.º 15
0
static void
taus_set (taus_state_t * state, unsigned int s)
{
  if (s == 0) {
    s = 1;      /* default seed is 1 */
  }

// original for unsigned long int
//#define LCG(n) ((69069 * n) & 0xffffffffUL)
#define LCG(n) ((69069 * n))

  state->s1 = LCG (s);
  state->s2 = LCG (state->s1);
  state->s3 = LCG (state->s2);

  /* "warm it up" */
  taus_get (state);
  taus_get (state);
  taus_get (state);
  taus_get (state);
  taus_get (state);
  taus_get (state);
  return;
}
Ejemplo n.º 16
0
static void
r250_set (void *vstate, unsigned long int s)
{
  r250_state_t *state = (r250_state_t *) vstate;

  int i;

  if (s == 0)
    s = 1;      /* default seed is 1 */

  state->i = 0;

#define LCG(n) ((69069 * n) & 0xffffffffUL)

  for (i = 0; i < 250; i++)     /* Fill the buffer  */
    {
      s = LCG (s);
      state->x[i] = s;
    }

  {
    /* Masks for turning on the diagonal bit and turning off the
       leftmost bits */

    unsigned long int msb = 0x80000000UL;
    unsigned long int mask = 0xffffffffUL;

    for (i = 0; i < 32; i++)
      {
        int k = 7 * i + 3;      /* Select a word to operate on        */
        state->x[k] &= mask;    /* Turn off bits left of the diagonal */
        state->x[k] |= msb;     /* Turn on the diagonal bit           */
        mask >>= 1;
        msb >>= 1;
      }
  }

  return;
}
Ejemplo n.º 17
0
static void lcg_seed(void) /* {{{ */
{
	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) = (zend_long) tsrm_thread_id();
#else
	LCG(s2) = (zend_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;
}
Ejemplo n.º 18
0
static void pnl_mrgk3_sseed (mrgk3_state *s, ulong seed)
{
  if ( seed == 0 )
    {
      s->x10=231458761.;
      s->x11=34125679.;
      s->x12=45678213.;

      s->x20=57964412.;
      s->x21=12365487.;
      s->x22=77221456.;
    }
  else
    {
      const ulong M1   = 4294967087UL;
      const ulong M2   = 4294944443UL;
      ulong n = seed;
      n = LCG(n);
      s->x10 = n % M1;
      n = LCG(n);
      s->x11 = n % M1;
      n = LCG(n);
      s->x12 = n % M1;

      n = LCG(n);
      s->x20 = n % M2;
      n = LCG(n);
      s->x21 = n % M2;
      n = LCG(n);
      s->x22 = n % M2;

      /*
       * We should run the generator a few times to warm it up, but it
       * requires to change the header of sseed functions to pas them rng
       * object and not only the states
       */
    }
}
Ejemplo n.º 19
0
void Generator2::losuj()
{
	x = (LCG(mnoznik, x, modul) + add) % modul;

    this->iWylosowana = iPoczatek + (x % (iKoniec - iPoczatek + 1));
}
Ejemplo n.º 20
0
void mrgini(UL seed) {
  UL s, q = LCG(seed ? seed : 4357);
  s  = (q & 0xffff0000UL);        q = LCG(q);
  s |= (q & 0xffff0000UL) >> 16;  q = LCG(q);
  s10 = (double) (s<m1 ? s : s-m1);
  s  = (q & 0xffff0000UL);        q = LCG(q);
  s |= (q & 0xffff0000UL) >> 16;  q = LCG(q);
  s11 = (double) (s<m1 ? s : s-m1);
  s  = (q & 0xffff0000UL);        q = LCG(q);
  s |= (q & 0xffff0000UL) >> 16;  q = LCG(q);
  s12 = (double) (s<m1 ? s : s-m1);
  s  = (q & 0xffff0000UL);        q = LCG(q);
  s |= (q & 0xffff0000UL) >> 16;  q = LCG(q);
  s20 = (double) (s<m2 ? s : s-m2);
  s  = (q & 0xffff0000UL);        q = LCG(q);
  s |= (q & 0xffff0000UL) >> 16;  q = LCG(q);
  s21 = (double) (s<m2 ? s : s-m2);
  s  = (q & 0xffff0000UL);        q = LCG(q);
  s |= (q & 0xffff0000UL) >> 16;  q = LCG(q);
  s22 = (double) (s<m2 ? s : s-m2);
}
Ejemplo n.º 21
0
static void lcg_init_globals(php_lcg_globals *lcg_globals_p) /* {{{ */
{
	LCG(seeded) = 0;
}