src/metaspades/ext/src/easel/esl_random.c
/* Function:  esl_randomness_Create()
 * Synopsis:  Create the default strong random number generator.
 *
 * Purpose:   Create a random number generator using
 *            a given random seed. The <seed> must be $\geq 0$.
 *            
 *            The default random number generator uses the Mersenne
 *            Twister MT19937 algorithm \citep{Matsumoto98}.  It has a
 *            period of $2^{19937}-1$, and equidistribution over
 *            $2^{32}$ values.
 *
 *            If <seed> is $>0$, the random number generator is
 *            reproducibly initialized with that seed.  Two RNGs
 *            created with the same nonzero seed will give exactly the
 *            same stream of pseudorandom numbers. This allows you to
 *            make reproducible stochastic simulations, for example.
 *            
 *            If <seed> is 0, an arbitrary seed is chosen.
 *            Internally, the arbitrary seed is produced by a
 *            combination of the current <time()> and the process id
 *            (if available; POSIX only). Two RNGs created with
 *            <seed>=0 will very probably (but not assuredly) give
 *            different streams of pseudorandom numbers. The true seed
 *            can be retrieved from the <ESL_RANDOMNESS> object using
 *            <esl_randomness_GetSeed()>.  The strategy used for
 *            choosing the arbitrary seed is predictable, so it is
 *            not secure in any sense, especially in the cryptographic
 *            sense.
 *            
 * Args:      seed $>= 0$.
 *
 * Returns:   an initialized <ESL_RANDOMNESS *> on success.
 *            Caller free's with <esl_randomness_Destroy()>.
 *              
 * Throws:    <NULL> on failure.
 * 
 * Xref:      SRE:STL8/p57.
 *            SRE:J5/21:    Mersenne Twister.
 */
esl_randomness_Create()
Synopsis:  Create the default strong random number generator.

Create a random number generator using
a given random seed. The  must be $\geq 0$.

The default random number generator uses the Mersenne
Twister MT19937 algorithm \citep{Matsumoto98}.  It has a
period of $2^{19937}-1$, and equidistribution over
$2^{32}$ values.

If  is $>0$, the random number generator is
reproducibly initialized with that seed.  Two RNGs
created with the same nonzero seed will give exactly the
same stream of pseudorandom numbers. This allows you to
make reproducible stochastic simulations, for example.

If  is 0, an arbitrary seed is chosen.
Internally, the arbitrary seed is produced by a
combination of the current  and the process id
(if available; POSIX only). Two RNGs created with
=0 will very probably (but not assuredly) give
different streams of pseudorandom numbers. The true seed
can be retrieved from the  object using
.  The strategy used for
choosing the arbitrary seed is predictable, so it is
not secure in any sense, especially in the cryptographic
sense.



an initialized  on success.
Caller free's with .

 on failure.


esl_randomness_Create () Synopsis : Create the default strong random number generator . Create a random number generator using a given random seed . The must be $ \ geq 0$ . The default random number generator uses the Mersenne Twister MT19937 algorithm \ citep { Matsumoto98 } . It has a period of $2^ { 19937 } - 1$ and equidistribution over $2^ { 32 } $ values . If is $ > 0$ the random number generator is reproducibly initialized with that seed . Two RNGs created with the same nonzero seed will give exactly the same stream of pseudorandom numbers . This allows you to make reproducible stochastic simulations for example . If is 0 an arbitrary seed is chosen . Internally the arbitrary seed is produced by a combination of the current and the process id ( if available ; POSIX only ) . Two RNGs created with = 0 will very probably ( but not assuredly ) give different streams of pseudorandom numbers . The true seed can be retrieved from the object using . The strategy used for choosing the arbitrary seed is predictable so it is not secure in any sense especially in the cryptographic sense . an initialized on success . Caller free ' s with . on failure .
ESL_RANDOMNESS *
esl_randomness_Create(uint32_t seed)
{
  ESL_RANDOMNESS *r      = NULL;
  int             status;
  ESL_ALLOC(r, sizeof(ESL_RANDOMNESS));
  r->type = eslRND_MERSENNE;
  r->mti  = 0;
  r->x    = 0;
  r->seed = 0;
  esl_randomness_Init(r, seed);
  return r;
 ERROR:
  return NULL;
}
ESL_RANDOMNESS * esl_randomness_Create ( uint32_t seed ) { ESL_RANDOMNESS * r = NULL ; int status ; ESL_ALLOC ( r , sizeof ( ESL_RANDOMNESS ) ) ; r -> type = eslRND_MERSENNE ; r -> mti = 0 ; r -> x = 0 ; r -> seed = 0 ; esl_randomness_Init ( r , seed ) ; return r ; ERROR : return NULL ; }
Function:  esl_randomness_Create()
 Synopsis:  Create the default strong random number generator.
Function : esl_randomness_Create () Synopsis : Create the default strong random number generator .