/* Mersenne Twister pseudo-random number generator functions.
THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY . THEY ' RE ALMOST
CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
FUTURE GNU MP RELEASES .
Copyright 2002 , 2003 , 2006 Free Software Foundation , Inc .
This file is part of the GNU MP Library .
The GNU MP Library is free software ; you can redistribute it and / or modify
it under the terms of either :
* the GNU Lesser General Public License as published by the Free
Software Foundation ; either version 3 of the License , or ( at your
option ) any later version .
or
* the GNU General Public License as published by the Free Software
Foundation ; either version 2 of the License , or ( at your option ) any
later version .
or both in parallel , as here .
The GNU MP Library is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License
for more details .
You should have received copies of the GNU General Public License and the
GNU Lesser General Public License along with the GNU MP Library . If not ,
see https://www.gnu.org/licenses/. */
#include <stdio.h>
/* for NULL */
#include "gmp-impl.h"
#include "randmt.h"
/* This code implements the Mersenne Twister pseudorandom number generator
by Takuji Nishimura and Makoto Matsumoto . The buffer initialization
function is different in order to permit seeds greater than 2 ^ 32 - 1 .
This file contains a special _ _ gmp_randinit_mt_noseed which excludes the
seeding function from the gmp_randfnptr_t routines . This is for use by
mpn_random and mpn_random2 on the global random generator . MT seeding
uses mpz functions , and we don ' t want mpn routines dragging mpz functions
into the link. */
/* Default seed to use when the generator is not initialized. */
#define DEFAULT_SEED
5489 /* was 4357 */
/* Tempering masks. */
#define MASK_1
0 x9D2C5680
#define MASK_2
0 xEFC60000
/* Initial state of buffer when initialized with default seed. */
static const gmp_uint_least32_t default_state[N] =
{
0 xD247B233,
0 x9E5AA8F1,
0 x0FFA981B,
0 x9DCB0980,
0 x74200F2B,
0 xA576D044,
0 xE9F05ADF,
0 x1538BFF5,
0 x59818BBF,
0 xCF9E58D8,
0 x09FCE032,
0 x6A1C663F,
0 x5116E78A,
0 x69B3E0FA,
0 x6D92D665,
0 xD0A8BE98,
0 xF669B734,
0 x41AC1B68,
0 x630423F1,
0 x4B8D6B8A,
0 xC2C46DD7,
0 x5680747D,
0 x43703E8F,
0 x3B6103D2,
0 x49E5EB3F,
0 xCBDAB4C1,
0 x9C988E23,
0 x747BEE0B,
0 x9111E329,
0 x9F031B5A,
0 xECCA71B9,
0 x2AFE4EF8,
0 x8421C7ED,
0 xAC89AFF1,
0 xAED90DF3,
0 x2DD74F01,
0 x14906A13,
0 x75873FA9,
0 xFF83F877,
0 x5028A0C9,
0 x11B4C41D,
0 x7CAEDBC4,
0 x8672D0A7,
0 x48A7C109,
0 x8320E59F,
0 xBC0B3D5F,
0 x75A30886,
0 xF9E0D128,
0 x41AF7580,
0 x239BB94D,
0 xC67A3C81,
0 x74EEBD6E,
0 xBC02B53C,
0 x727EA449,
0 x6B8A2806,
0 x5853B0DA,
0 xBDE032F4,
0 xCE234885,
0 x320D6145,
0 x48CC053F,
0 x00DBC4D2,
0 xD55A2397,
0 xE1059B6F,
0 x1C3E05D1,
0 x09657C64,
0 xD07CB661,
0 x6E982E34,
0 x6DD1D777,
0 xEDED1071,
0 xD79DFD65,
0 xF816DDCE,
0 xB6FAF1E4,
0 x1C771074,
0 x311835BD,
0 x18F952F7,
0 xF8F40350,
0 x4ECED354,
0 x7C8AC12B,
0 x31A9994D,
0 x4FD47747,
0 xDC227A23,
0 x6DFAFDDF,
0 x6796E748,
0 x0C6F634F,
0 xF992FA1D,
0 x4CF670C9,
0 x067DFD31,
0 xA7A3E1A5,
0 x8CD7D9DF,
0 x972CCB34,
0 x67C82156,
0 xD548F6A8,
0 x045CEC21,
0 xF3240BFB,
0 xDEF656A7,
0 x43DE08C5,
0 xDAD1F92F,
0 x3726C56B,
0 x1409F19A,
0 x942FD147,
0 xB926749C,
0 xADDC31B8,
0 x53D0D869,
0 xD1BA52FE,
0 x6722DF8C,
0 x22D95A74,
0 x7DC1B52A,
0 x1DEC6FD5,
0 x7262874D,
0 x0A725DC9,
0 xE6A8193D,
0 xA052835A,
0 xDC9AD928,
0 xE59EBB90,
0 x70DBA9FF,
0 xD612749D,
0 x5A5A638C,
0 x6086EC37,
0 x2A579709,
0 x1449EA3A,
0 xBC8E3C06,
0 x2F900666,
0 xFBE74FD1,
0 x6B35B911,
0 xF8335008,
0 xEF1E979D,
0 x738AB29D,
0 xA2DC0FDC,
0 x7696305D,
0 xF5429DAC,
0 x8C41813B,
0 x8073E02E,
0 xBEF83CCD,
0 x7B50A95A,
0 x05EE5862,
0 x00829ECE,
0 x8CA1958C,
0 xBE4EA2E2,
0 x4293BB73,
0 x656F7B23,
0 x417316D8,
0 x4467D7CF,
0 x2200E63B,
0 x109050C8,
0 x814CBE47,
0 x36B1D4A8,
0 x36AF9305,
0 x308327B3,
0 xEBCD7344,
0 xA738DE27,
0 x5A10C399,
0 x4142371D,
0 x64A18528,
0 x0B31E8B2,
0 x641057B9,
0 x6AFC363B,
0 x108AD953,
0 x9D4DA234,
0 x0C2D9159,
0 x1C8A1A1F,
0 x310C66BA,
0 x87AA1070,
0 xDAC832FF,
0 x0A433422,
0 x7AF15812,
0 x2D8D9BD0,
0 x995A25E9,
0 x25326CAC,
0 xA34384DB,
0 x4C8421CC,
0 x4F0315EC,
0 x29E8649E,
0 xA7732D6F,
0 x2E94D3E3,
0 x7D98A340,
0 x397C4D74,
0 x659DB4DE,
0 x747D4E9A,
0 xD9DB8435,
0 x4659DBE9,
0 x313E6DC5,
0 x29D104DC,
0 x9F226CBA,
0 x452F18B0,
0 xD0BC5068,
0 x844CA299,
0 x782B294E,
0 x4AE2EB7B,
0 xA4C475F8,
0 x70A81311,
0 x4B3E8BCC,
0 x7E20D4BA,
0 xABCA33C9,
0 x57BE2960,
0 x44F9B419,
0 x2E567746,
0 x72EB757A,
0 x102CC0E8,
0 xB07F32B9,
0 xD0DABD59,
0 xBA85AD6B,
0 xF3E20667,
0 x98D77D81,
0 x197AFA47,
0 x518EE9AC,
0 xE10CE5A2,
0 x01CF2C2A,
0 xD3A3AF3D,
0 x16DDFD65,
0 x669232F8,
0 x1C50A301,
0 xB93D9151,
0 x9354D3F4,
0 x847D79D0,
0 xD5FE2EC6,
0 x1F7B0610,
0 xFA6B90A5,
0 xC5879041,
0 x2E7DC05E,
0 x423F1F32,
0 xEF623DDB,
0 x49C13280,
0 x98714E92,
0 xC7B6E4AD,
0 xC4318466,
0 x0737F312,
0 x4D3C003F,
0 x9ACC1F1F,
0 x5F1C926D,
0 x085FA771,
0 x185A83A2,
0 xF9AA159D,
0 x0B0B0132,
0 xF98E7A43,
0 xCD9EBDBE,
0 x0190CB29,
0 x10D93FB6,
0 x3B8A4D97,
0 x66A65A41,
0 xE43E766F,
0 x77BE3C41,
0 xB9686364,
0 xCB36994D,
0 x6846A287,
0 x567E77F7,
0 x36178DD8,
0 xBDE6B1F2,
0 xB6EFDC64,
0 x82950324,
0 x42053F47,
0 xC09BE51C,
0 x0942D762,
0 x35F92C7F,
0 x367DEC61,
0 x6EE3D983,
0 xDBAAF78A,
0 x265D2C47,
0 x8EB4BF5C,
0 x33B232D7,
0 xB0137E77,
0 x373C39A7,
0 x8D2B2E76,
0 xC7510F01,
0 x50F9E032,
0 x7B1FDDDB,
0 x724C2AAE,
0 xB10ECB31,
0 xCCA3D1B8,
0 x7F0BCF10,
0 x4254BBBD,
0 xE3F93B97,
0 x2305039B,
0 x53120E22,
0 x1A2F3B9A,
0 x0FDDBD97,
0 x0118561E,
0 x0A798E13,
0 x9E0B3ACD,
0 xDB6C9F15,
0 xF512D0A2,
0 x9E8C3A28,
0 xEE2184AE,
0 x0051EC2F,
0 x2432F74F,
0 xB0AA66EA,
0 x55128D88,
0 xF7D83A38,
0 x4DAE8E82,
0 x3FDC98D6,
0 x5F0BD341,
0 x7244BE1D,
0 xC7B48E78,
0 x2D473053,
0 x43892E20,
0 xBA0F1F2A,
0 x524D4895,
0 x2E10BCB1,
0 x4C372D81,
0 x5C3E50CD,
0 xCF61CC2E,
0 x931709AB,
0 x81B3AEFC,
0 x39E9405E,
0 x7FFE108C,
0 x4FBB3FF8,
0 x06ABE450,
0 x7F5BF51E,
0 xA4E3CDFD,
0 xDB0F6C6F,
0 x159A1227,
0 x3B9FED55,
0 xD20B6F7F,
0 xFBE9CC83,
0 x64856619,
0 xBF52B8AF,
0 x9D7006B0,
0 x71165BC6,
0 xAE324AEE,
0 x29D27F2C,
0 x794C2086,
0 x74445CE2,
0 x782915CC,
0 xD4CE6886,
0 x3289AE7C,
0 x53DEF297,
0 x4185F7ED,
0 x88B72400,
0 x3C09DC11,
0 xBCE3AAB6,
0 x6A75934A,
0 xB267E399,
0 x000DF1BF,
0 x193BA5E2,
0 xFA3E1977,
0 x179E14F6,
0 x1EEDE298,
0 x691F0B06,
0 xB84F78AC,
0 xC1C15316,
0 xFFFF3AD6,
0 x0B457383,
0 x518CD612,
0 x05A00F3E,
0 xD5B7D275,
0 x4C5ECCD7,
0 xE02CD0BE,
0 x5558E9F2,
0 x0C89BBF0,
0 xA3D96227,
0 x2832D2B2,
0 xF667B897,
0 xD4556554,
0 xF9D2F01F,
0 xFA1E3FAE,
0 x52C2E1EE,
0 xE5451F31,
0 x7E849729,
0 xDABDB67A,
0 x54BF5E7E,
0 xF831C271,
0 x5F1A17E3,
0 x9D140AFE,
0 x92741C47,
0 x48CFABCE,
0 x9CBBE477,
0 x9C3EE57F,
0 xB07D4C39,
0 xCC21BCE2,
0 x697708B1,
0 x58DA2A6B,
0 x2370DB16,
0 x6E641948,
0 xACC5BD52,
0 x868F24CC,
0 xCA1DB0F5,
0 x4CADA492,
0 x3F443E54,
0 xC4A4D5E9,
0 xF00AD670,
0 xE93C86E0,
0 xFE90651A,
0 xDDE532A3,
0 xA66458DF,
0 xAB7D7151,
0 x0E2E775F,
0 xC9109F99,
0 x8D96D59F,
0 x73CEF14C,
0 xC74E88E9,
0 x02712DC0,
0 x04F41735,
0 x2E5914A2,
0 x59F4B2FB,
0 x0287FC83,
0 x80BC0343,
0 xF6B32559,
0 xC74178D4,
0 xF1D99123,
0 x383CCC07,
0 xACC0637D,
0 x0863A548,
0 xA6FCAC85,
0 x2A13EFF0,
0 xAF2EEDB1,
0 x41E72750,
0 xE0C6B342,
0 x5DA22B46,
0 x635559E0,
0 xD2EA40AC,
0 x10AA98C0,
0 x19096497,
0 x112C542B,
0 x2C85040C,
0 xA868E7D0,
0 x6E260188,
0 xF596D390,
0 xC3BB5D7A,
0 x7A2AA937,
0 xDFD15032,
0 x6780AE3B,
0 xDB5F9CD8,
0 x8BD266B0,
0 x7744AF12,
0 xB463B1B0,
0 x589629C9,
0 xE30DBC6E,
0 x880F5569,
0 x209E6E16,
0 x9DECA50C,
0 x02987A57,
0 xBED3EA57,
0 xD3A678AA,
0 x70DD030D,
0 x0CFD9C5D,
0 x92A18E99,
0 xF5740619,
0 x7F6F0A7D,
0 x134CAF9A,
0 x70F5BAE4,
0 x23DCA7B5,
0 x4D788FCD,
0 xC7F07847,
0 xBCF77DA1,
0 x9071D568,
0 xFC627EA1,
0 xAE004B77,
0 x66B54BCB,
0 x7EF2DAAC,
0 xDCD5AC30,
0 xB9BDF730,
0 x505A97A7,
0 x9D881FD3,
0 xADB796CC,
0 x94A1D202,
0 x97535D7F,
0 x31EC20C0,
0 xB1887A98,
0 xC1475069,
0 xA6F73AF3,
0 x71E4E067,
0 x46A569DE,
0 xD2ADE430,
0 x6F0762C7,
0 xF50876F4,
0 x53510542,
0 x03741C3E,
0 x53502224,
0 xD8E54D60,
0 x3C44AB1A,
0 x34972B46,
0 x74BFA89D,
0 xD7D768E0,
0 x37E605DC,
0 xE13D1BDF,
0 x5051C421,
0 xB9E057BE,
0 xB717A14C,
0 xA1730C43,
0 xB99638BE,
0 xB5D5F36D,
0 xE960D9EA,
0 x6B1388D3,
0 xECB6D3B6,
0 xBDBE8B83,
0 x2E29AFC5,
0 x764D71EC,
0 x4B8F4F43,
0 xC21DDC00,
0 xA63F657F,
0 x82678130,
0 xDBF535AC,
0 xA594FC58,
0 x942686BC,
0 xBD9B657B,
0 x4A0F9B61,
0 x44FF184F,
0 x38E10A2F,
0 x61910626,
0 x5E247636,
0 x7106D137,
0 xC62802F0,
0 xBD1D1F00,
0 x7CC0DCB2,
0 xED634909,
0 xDC13B24E,
0 x9799C499,
0 xD77E3D6A,
0 x14773B68,
0 x967A4FB7,
0 x35EECFB1,
0 x2A5110B8,
0 xE2F0AF94,
0 x9D09DEA5,
0 x20255D27,
0 x5771D34B,
0 xE1089EE4,
0 x246F330B,
0 x8F7CAEE5,
0 xD3064712,
0 x75CAFBEE,
0 xB94F7028,
0 xED953666,
0 x5D1975B4,
0 x5AF81271,
0 x13BE2025,
0 x85194659,
0 x30805331,
0 xEC9D46C0,
0 xBC027C36,
0 x2AF84188,
0 xC2141B80,
0 xC02B1E4A,
0 x04D36177,
0 xFC50E9D7,
0 x39CE79DA,
0 x917E0A00,
0 xEF7A0BF4,
0 xA98BD8D1,
0 x19424DD2,
0 x9439DF1F,
0 xC42AF746,
0 xADDBE83E,
0 x85221F0D,
0 x45563E90,
0 x9095EC52,
0 x77887B25,
0 x8AE46064,
0 xBD43B71A,
0 xBB541956,
0 x7366CF9D,
0 xEE8E1737,
0 xB5A727C9,
0 x5076B3E7,
0 xFC70BACA,
0 xCE135B75,
0 xC4E91AA3,
0 xF0341911,
0 x53430C3F,
0 x886B0824,
0 x6BB5B8B7,
0 x33E21254,
0 xF193B456,
0 x5B09617F,
0 x215FFF50,
0 x48D97EF1,
0 x356479AB,
0 x6EA9DDC4,
0 x0D352746,
0 xA2F5CE43,
0 xB226A1B3,
0 x1329EA3C,
0 x7A337CC2,
0 xB5CCE13D,
0 x563E3B5B,
0 x534E8E8F,
0 x561399C9,
0 xE1596392,
0 xB0F03125,
0 x4586645B,
0 x1F371847,
0 x94EAABD1,
0 x41F97EDD,
0 xE3E5A39B,
0 x71C774E2,
0 x507296F4,
0 x5960133B,
0 x7852C494,
0 x3F5B2691,
0 xA3F87774,
0 x5A7AF89E,
0 x17DA3F28,
0 xE9D9516D,
0 xFCC1C1D5,
0 xE4618628,
0 x04081047,
0 xD8E4DB5F,
0 xDC380416,
0 x8C4933E2,
0 x95074D53,
0 xB1B0032D,
0 xCC8102EA,
0 x71641243,
0 x98D6EB6A,
0 x90FEC945,
0 xA0914345,
0 x6FAB037D,
0 x70F49C4D,
0 x05BF5B0E,
0 x927AAF7F,
0 xA1940F61,
0 xFEE0756F,
0 xF815369F,
0 x5C00253B,
0 xF2B9762F,
0 x4AEB3CCC,
0 x1069F386,
0 xFBA4E7B9,
0 x70332665,
0 x6BCA810E,
0 x85AB8058,
0 xAE4B2B2F,
0 x9D120712,
0 xBEE8EACB,
0 x776A1112
};
void
__gmp_mt_recalc_buffer (gmp_uint_least32_t mt[])
{
gmp_uint_least32_t y;
int kk;
for (kk =
0 ; kk < N - M; kk++)
{
y = (mt[kk] &
0 x80000000) | (mt[kk +
1 ] &
0 x7FFFFFFF);
mt[kk] = mt[kk + M] ^ (y >>
1 ) ^ ((y &
0 x01) !=
0 ? MATRIX_A :
0 );
}
for (; kk < N -
1 ; kk++)
{
y = (mt[kk] &
0 x80000000) | (mt[kk +
1 ] &
0 x7FFFFFFF);
mt[kk] = mt[kk - (N - M)] ^ (y >>
1 ) ^ ((y &
0 x01) !=
0 ? MATRIX_A :
0 );
}
y = (mt[N -
1 ] &
0 x80000000) | (mt[
0 ] &
0 x7FFFFFFF);
mt[N -
1 ] = mt[M -
1 ] ^ (y >>
1 ) ^ ((y &
0 x01) !=
0 ? MATRIX_A :
0 );
}
/* Get nbits bits of output from the generator into dest.
Note that Mersenne Twister is designed to produce outputs in
32-bit words. */
void
__gmp_randget_mt (gmp_randstate_ptr rstate, mp_ptr dest,
unsigned long int nbits)
{
gmp_uint_least32_t y;
int rbits;
mp_size_t i;
mp_size_t nlimbs;
int *pmti;
gmp_uint_least32_t *mt;
pmti = &((gmp_rand_mt_struct *) RNG_STATE (rstate))->mti;
mt = ((gmp_rand_mt_struct *) RNG_STATE (rstate))->mt;
nlimbs = nbits / GMP_NUMB_BITS;
rbits = nbits % GMP_NUMB_BITS;
#define NEXT_RANDOM \
do \
{ \
if (*pmti >= N) \
{ \
__gmp_mt_recalc_buffer (mt); \
*pmti =
0 ; \
} \
y = mt[(*pmti)++]; \
y ^= (y >>
11 ); \
y ^= (y <<
7 ) & MASK_1; \
y ^= (y <<
15 ) & MASK_2; \
y ^= (y >>
18 ); \
} \
while (
0 )
/* Handle the common cases of 32- or 64-bit limbs with fast,
optimized routines , and the rest of cases with a general
routine . In all cases , no more than 31 bits are rejected
for the last limb so that every version of the code is
consistent with the others. */
#if (GMP_NUMB_BITS ==
32 )
for (i =
0 ; i < nlimbs; i++)
{
NEXT_RANDOM;
dest[i] = (mp_limb_t) y;
}
if (rbits)
{
NEXT_RANDOM;
dest[nlimbs] = (mp_limb_t) (y & ~(ULONG_MAX << rbits));
}
#else /* GMP_NUMB_BITS != 32 */
#if (GMP_NUMB_BITS ==
64 )
for (i =
0 ; i < nlimbs; i++)
{
NEXT_RANDOM;
dest[i] = (mp_limb_t) y;
NEXT_RANDOM;
dest[i] |= (mp_limb_t) y <<
32 ;
}
if (rbits)
{
if (rbits <
32 )
{
NEXT_RANDOM;
dest[nlimbs] = (mp_limb_t) (y & ~(ULONG_MAX << rbits));
}
else
{
NEXT_RANDOM;
dest[nlimbs] = (mp_limb_t) y;
if (rbits >
32 )
{
NEXT_RANDOM;
dest[nlimbs] |=
((mp_limb_t) (y & ~(ULONG_MAX << (rbits-
32 )))) <<
32 ;
}
}
}
#else /* GMP_NUMB_BITS != 64 */
{
/* Fall back to a general algorithm. This algorithm works by
keeping a pool of up to 64 bits ( 2 outputs from MT ) acting
as a shift register from which bits are consumed as needed .
Bits are consumed using the LSB bits of bitpool_l , and
inserted via bitpool_h and shifted to the right place. */
gmp_uint_least32_t bitpool_h =
0 ;
gmp_uint_least32_t bitpool_l =
0 ;
int bits_in_pool =
0 ;
/* Holds number of valid bits in the pool. */
int bits_to_fill;
/* Holds total number of bits to put in
destination. */
int bitidx;
/* Holds the destination bit position. */
mp_size_t nlimbs2;
/* Number of whole+partial limbs to fill. */
nlimbs2 = nlimbs + (rbits !=
0 );
for (i =
0 ; i < nlimbs2; i++)
{
bitidx =
0 ;
if (i < nlimbs)
bits_to_fill = GMP_NUMB_BITS;
else
bits_to_fill = rbits;
dest[i] = CNST_LIMB (
0 );
while (bits_to_fill >=
32 )
/* Process whole 32-bit blocks first. */
{
if (bits_in_pool <
32 )
/* Need more bits. */
{
/* 64-bit right shift. */
NEXT_RANDOM;
bitpool_h = y;
bitpool_l |= (bitpool_h << bits_in_pool) &
0 xFFFFFFFF;
if (bits_in_pool ==
0 )
bitpool_h =
0 ;
else
bitpool_h >>=
32 - bits_in_pool;
bits_in_pool +=
32 ;
/* We've got 32 more bits. */
}
/* Fill a 32-bit chunk. */
dest[i] |= ((mp_limb_t) bitpool_l) << bitidx;
bitpool_l = bitpool_h;
bits_in_pool -=
32 ;
bits_to_fill -=
32 ;
bitidx +=
32 ;
}
/* Cover the case where GMP_NUMB_BITS is not a multiple of 32. */
if (bits_to_fill !=
0 )
{
if (bits_in_pool < bits_to_fill)
{
NEXT_RANDOM;
bitpool_h = y;
bitpool_l |= (bitpool_h << bits_in_pool) &
0 xFFFFFFFF;
if (bits_in_pool ==
0 )
bitpool_h =
0 ;
else
bitpool_h >>=
32 - bits_in_pool;
bits_in_pool +=
32 ;
}
dest[i] |= (((mp_limb_t) bitpool_l
& ~(~CNST_LIMB (
0 ) << bits_to_fill))
<< bitidx);
bitpool_l = ((bitpool_l >> bits_to_fill)
| (bitpool_h << (
32 - bits_to_fill))) &
0 xFFFFFFFF;
bitpool_h >>= bits_to_fill;
bits_in_pool -= bits_to_fill;
}
}
}
#endif /* GMP_NUMB_BITS != 64 */
#endif /* GMP_NUMB_BITS != 32 */
}
void
__gmp_randclear_mt (gmp_randstate_ptr rstate)
{
(*__gmp_free_func) ((
void *) RNG_STATE (rstate),
ALLOC (rstate->_mp_seed) * GMP_LIMB_BYTES);
}
void __gmp_randiset_mt (gmp_randstate_ptr, gmp_randstate_srcptr);
static const gmp_randfnptr_t Mersenne_Twister_Generator_Noseed = {
NULL,
__gmp_randget_mt,
__gmp_randclear_mt,
__gmp_randiset_mt
};
void
__gmp_randiset_mt (gmp_randstate_ptr dst, gmp_randstate_srcptr src)
{
const mp_size_t sz = ((
sizeof (gmp_rand_mt_struct) -
1 ) / GMP_LIMB_BYTES) +
1 ;
gmp_rand_mt_struct *dstp, *srcp;
mp_size_t i;
/* Set the generator functions. */
RNG_FNPTR (dst) = RNG_FNPTR(src);
/* Allocate the MT-specific state. */
dstp = (gmp_rand_mt_struct *) __GMP_ALLOCATE_FUNC_LIMBS (sz);
RNG_STATE (dst) = (mp_ptr) dstp;
ALLOC (dst->_mp_seed) = sz;
/* Initialize alloc field to placate Camm. */
/* Copy state. */
srcp = (gmp_rand_mt_struct *) RNG_STATE (src);
for (i =
0 ; i < N; i++)
dstp->mt[i] = srcp->mt[i];
dstp->mti = srcp->mti;
}
void
__gmp_randinit_mt_noseed (gmp_randstate_ptr dst)
{
const mp_size_t sz = ((
sizeof (gmp_rand_mt_struct) -
1 ) / GMP_LIMB_BYTES) +
1 ;
gmp_rand_mt_struct *dstp;
mp_size_t i;
/* Set the generator functions. */
RNG_FNPTR (dst) = (
void *) &Mersenne_Twister_Generator_Noseed;
/* Allocate the MT-specific state. */
dstp = (gmp_rand_mt_struct *) __GMP_ALLOCATE_FUNC_LIMBS (sz);
RNG_STATE (dst) = (mp_ptr) dstp;
ALLOC (dst->_mp_seed) = sz;
/* Initialize alloc field to placate Camm. */
/* Set state for default seed. */
for (i =
0 ; i < N; i++)
dstp->mt[i] = default_state[i];
dstp->mti = WARM_UP % N;
}
Messung V0.5 in Prozent C=94 H=84 G=88
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-09-29)
¤
*© Formatika GbR, Deutschland