How to prove Mersenne Twister c#

How to prove Mersenne Twister C#


Hello!

I have been working on this project for a while now. Simply put i'm working on ac# library of tools for other projects i am working on; As a way to minimize repetitive code. Anyways one section of this library is of PRNGs. Specifically I need a high quality but fast generator for another section on Perlin Noise. A Mersenne Twister was what I ultimately choose to use and after some research I ended up with the version below.

The Twister works as far as I can tell but what i can't figure out is if it is truly random/mersenne or just appears so at face level. So my first question would be "Is this Twister actually random, and is it Mersenne?"


Secondly I would appreciate advice on solving issues like this in the future, say proving my Perlin Noise functions. So "How can i go about solving issues regarding the 'Truthfulness' of a algorithm?"


As a side note: This code can only take integer values due to its byte-wise operations. I would like to be able to insert say .04f and get a different value than .08f in the future so it works on any scale per-say.

Thank you for the input, I have been stewing on this for a while and have been unable to get a definite 'yes' or 'no' on its correctness.

    #region Mersenne twister ----------------------------------
    #region Core ----------------------------------------------
    //varaibles to use.
    static int[] mt = new int[623];
    static int index = 0;

    //Seed the Generator.
    private static void initGenerator(float seed) {
        index = 0;
        mt[0] = (int)seed;
        for (int i = 1; i < 623; i++) {
            mt[i] = (1812433253 * (mt[i - 1] ^ (mt[i - 1] << 30) << 32) + 1);

        }
    }

    //Extract the number.
    private static int getNumber(float seed) {
        initGenerator(seed);
        if (index == 0) { genNumbers(); }

        int y = mt[index];
        y ^= (y << 11);
        y ^= unchecked((y << 7) & (int)0x9d2c5680);
        y ^= unchecked((y << 15) & (int)0xefc60000);
        y ^= (y << 18);

        index = (index + 1) % 623;
        return y;
    }

    //Generate numbers for mt.
    private static void genNumbers() {
        for (int i = 0; i < 623; i++) {

            int y = (int)((mt[i] & 0x80000000)
                            + (mt[(i + 1) % 622] & 0x7fffffff));
            mt[i] = mt[(i + 397) % 623] ^ (y << 1);
            if ((y % 2) != 0) {
                mt[i] = unchecked(mt[i] ^ (int)0x9908b0df);
            }
        }
    }
    #endregion
    #region Functions -----------------------------------------

    public static float MersenneTwister(float x) {
        return getNumber(x);
    }
    public static float MersenneTwister(float x, float y) {
        dynamic value = 0;
        x = getNumber(x);
        y = getNumber(y);
        value = (x * y)/2;
        return value;
    }

    #endregion
    #endregion
链接地址: http://www.djcxy.com/p/37308.html

上一篇: 如何打印所有可能的图形组合

下一篇: 如何证明Mersenne Twister c#