public void Copy(SfmtPrimitiveState source) { for (var i = 0; i < IntegerDefinition.N64; i++) { State->u64[i] = source.State->u64[i]; } }
public static void Jump(SfmtPrimitiveState sfmt, string jumpString) { const byte a = 0x61; const byte f = 0x66; const byte c0 = 0x30; var data = Encoding.ASCII.GetBytes(jumpString);
public static void GenRandAll(SfmtPrimitiveState sfmt) { int i; var pstate = sfmt.State; var r1 = pstate[N - 2].si; var r2 = pstate[N - 1].si; for (i = 0; i < N - Pos1; i++) { pstate[i].si = Recursion(pstate[i].si, pstate[i + Pos1].si, r1, r2); r1 = r2; r2 = pstate[i].si; } for (; i < N; i++) { pstate[i].si = Recursion(pstate[i].si, pstate[i + Pos1 - N].si, r1, r2); r1 = r2; r2 = pstate[i].si; } }
public static uint GenRandUint32(SfmtPrimitiveState sfmt) { var psfmt32 = &sfmt.State[0].u[0]; if (sfmt.Index >= N32) { GenRandAll(sfmt); sfmt.Index = 0; } var r = psfmt32[sfmt.Index++]; return(r); }
public static ulong GenRandUint64(SfmtPrimitiveState sfmt) { var psfmt64 = &sfmt.State[0].u64[0]; Trace.Assert(sfmt.Index % 2 == 0); if (sfmt.Index >= N32) { GenRandAll(sfmt); sfmt.Index = 0; } var r = psfmt64[sfmt.Index / 2]; sfmt.Index += 2; return(r); }
private static void NextState(SfmtPrimitiveState sfmt) { var idx = sfmt.Index / 4 % N; var pstate = sfmt.State; var r1 = &pstate[(idx + N - 2) % N]; var r2 = &pstate[(idx + N - 1) % N]; DoRecursion(&pstate[idx], &pstate[idx], &pstate[(idx + Pos1) % N], r1, r2); r1 = r2; r2 = &pstate[idx]; sfmt.Index += 4; }
private static void GenRandArray(SfmtPrimitiveState sfmt, IntegerW128 *array, int size) { int i, j; Vector128 <int> r1, r2; var pstate = sfmt.State; r1 = pstate[N - 2].si; r2 = pstate[N - 1].si; for (i = 0; i < N - Pos1; i++) { array[i].si = Recursion(pstate[i].si, pstate[i + Pos1].si, r1, r2); r1 = r2; r2 = array[i].si; } for (; i < N; i++) { array[i].si = Recursion(pstate[i].si, array[i + Pos1 - N].si, r1, r2); r1 = r2; r2 = array[i].si; } for (; i < size - N; i++) { array[i].si = Recursion(array[i - N].si, array[i + Pos1 - N].si, r1, r2); r1 = r2; r2 = array[i].si; } for (j = 0; j < 2 * N - size; j++) { pstate[j] = array[j + size - N]; } for (; i < size; i++, j++) { array[i].si = Recursion(array[i - N].si, array[i + Pos1 - N].si, r1, r2); r1 = r2; r2 = array[i].si; pstate[j] = array[i]; } }
public static void InitGenRand(SfmtPrimitiveState sfmt, uint seed) { unchecked { int i; var psfmt32 = &sfmt.State[0].u[0]; psfmt32[0] = seed; for (i = 1; i < N32; i++) { psfmt32[i] = (uint)(1812433253U * (psfmt32[i - 1] ^ (psfmt32[i - 1] >> 30)) + i); } sfmt.Index = N32; PeriodCertification(sfmt); } }
public static void FillArray32(SfmtPrimitiveState sfmt, AlignedArray <uint> array, int size) { if (sfmt.Index != N32) { throw new ArgumentException($"{nameof(sfmt)} internal state error."); } if (size % 4 != 0) { throw new ArgumentOutOfRangeException($"{nameof(size)} requires to be a multiple of four."); } if (size <= N32) { throw new ArgumentOutOfRangeException($"{nameof(size)} requires to be at least {N32}"); } GenRandArray(sfmt, (IntegerW128 *)array.StatusUncheckedPointer, size / 4); }
private static void Add(SfmtPrimitiveState dest, SfmtPrimitiveState src) { var dp = dest.Index / 4; var sp = src.Index / 4; var diff = (sp - dp + N) % N; int p; int i; for (i = 0; i < N - diff; i++) { p = i + diff; dest.State[i].si = Sse2.Xor(dest.State[i].si, src.State[p].si); } for (; i < N; i++) { p = i + diff - N; dest.State[i].si = Sse2.Xor(dest.State[i].si, src.State[p].si); } }
private static void PeriodCertification(SfmtPrimitiveState sfmt) { uint inner = 0; int i, j; var psfmt32 = &sfmt.State[0].u[0]; for (i = 0; i < 4; i++) { inner ^= psfmt32[i] & Parity[i]; } for (i = 16; i > 0; i >>= 1) { inner ^= inner >> i; } inner &= 1; /* check OK */ if (inner == 1) { return; } /* check NG, and modification */ for (i = 0; i < 4; i++) { uint work = 1; for (j = 0; j < 32; j++) { if ((work & Parity[i]) != 0) { psfmt32[i] ^= work; return; } work <<= 1; } } }
public static void InitByArray(SfmtPrimitiveState sfmt, ReadOnlySpan <uint> initKey) { unchecked {