Exemplo n.º 1
0
        public int sceKernelUtilsMt19937Init(out SceKernelUtilsMt19937Context Context, uint Seed)
        {
            fixed(uint *State = Context.State)
            {
                State[0] = Seed;

                for (int n = 1; n < SceKernelUtilsMt19937Context.MT_N; n++)
                {
                    State[n] = (uint)(1812433253 * (State[n - 1] ^ (State[n - 1] >> 30)) + n);
                }

                Context.Count = 0;

                for (int n = 0; n < SceKernelUtilsMt19937Context.MT_N; n++)
                {
                    sceKernelUtilsMt19937UInt(ref Context);
                }

                return(0);
            }
        }
Exemplo n.º 2
0
        public uint sceKernelUtilsMt19937UInt(ref SceKernelUtilsMt19937Context Context)
        {
            fixed(uint *State = Context.State)
            {
                uint *CurrentPointer;
                uint  Current, Next;
                uint  v0;
                bool  currentPosIsLess =
                    Context.Count < SceKernelUtilsMt19937Context.MT_N - SceKernelUtilsMt19937Context.MT_M;

                CurrentPointer = &State[Context.Count];

                // Current Value
                Current = *CurrentPointer;

                // Next Value
                Context.Count = (Context.Count + 1) % SceKernelUtilsMt19937Context.MT_N;
                Next          = State[Context.Count];

                v0  = Current ^ (Current >> 11);
                v0 ^= (v0 << 7) & 0x9D2C5680;
                v0 ^= (v0 << 15) & 0xEFC60000;

                var Mix = ((Current & 0x80000000) | (Next & 0x7FFFFFFF)) >> 1;

                if ((Next & 1) != 0)
                {
                    Current ^= 0x9908B0DF;
                }
                Mix ^= *(
                    currentPosIsLess
                        ? &CurrentPointer[+SceKernelUtilsMt19937Context.MT_M]
                        : &CurrentPointer[-(SceKernelUtilsMt19937Context.MT_N - SceKernelUtilsMt19937Context.MT_M)]
                    );
                *CurrentPointer = Mix;

                return(v0 ^ (v0 >> 18));
            }
        }
Exemplo n.º 3
0
        public uint sceKernelUtilsMt19937UInt(ref SceKernelUtilsMt19937Context Context)
        {
            fixed (uint* State = Context.State)
            {
                uint* CurrentPointer;
                uint Current, Next;
                uint v0;
                bool currentPosIsLess = Context.Count < (SceKernelUtilsMt19937Context.MT_N - SceKernelUtilsMt19937Context.MT_M);
                CurrentPointer = &State[Context.Count];

                // Current Value
                Current = *CurrentPointer;

                // Next Value
                Context.Count = (Context.Count + 1) % SceKernelUtilsMt19937Context.MT_N;
                Next = State[Context.Count];

                v0 = Current ^ (Current >> 11);
                v0 ^= ((v0 << 7) & 0x9D2C5680);
                v0 ^= ((v0 << 15) & 0xEFC60000);

                var Mix = ((Current & 0x80000000) | (Next & 0x7FFFFFFF)) >> 1;

                if ((Next & 1) != 0) Current ^= 0x9908B0DF;
                Mix ^= *(
                    currentPosIsLess
                    ? &CurrentPointer[+SceKernelUtilsMt19937Context.MT_M]
                    : &CurrentPointer[-(SceKernelUtilsMt19937Context.MT_N - SceKernelUtilsMt19937Context.MT_M)]
                );
                *CurrentPointer = Mix;

                return v0 ^ (v0 >> 18);
            }
        }
Exemplo n.º 4
0
        public int sceKernelUtilsMt19937Init(out SceKernelUtilsMt19937Context Context, uint Seed)
        {
            fixed (uint* State = Context.State)
            {
                State[0] = Seed;

                for (int n = 1; n < SceKernelUtilsMt19937Context.MT_N; n++)
                {
                    State[n] = (uint)(1812433253 * (State[n - 1] ^ (State[n - 1] >> 30)) + n);
                }

                Context.Count = 0;

                for (int n = 0; n < SceKernelUtilsMt19937Context.MT_N; n++)
                {
                    sceKernelUtilsMt19937UInt(ref Context);
                }

                return 0;
            }
        }
Exemplo n.º 5
0
 public uint sceKernelUtilsMt19937UInt(SceKernelUtilsMt19937Context* Context)
 {
     var Random = Randoms[(uint)Context];
     return (uint)Random.Next();
 }
Exemplo n.º 6
0
 public int sceKernelUtilsMt19937Init(SceKernelUtilsMt19937Context* Context, uint Seed)
 {
     Randoms.Add((uint)Context, new Random((int)Seed));
     return 0;
 }