]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
xorshift pseudo-random number generator
authorToni Wilen <twilen@winuae.net>
Sun, 6 Nov 2022 16:52:09 +0000 (18:52 +0200)
committerToni Wilen <twilen@winuae.net>
Sun, 6 Nov 2022 16:52:09 +0000 (18:52 +0200)
main.cpp

index 318109f50782c0075bf09865ea983d83db6e6edb..10f1cf337ac2bc766ea700c7460b142b9a1cbeb1 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -68,25 +68,33 @@ TCHAR optionsfile[256];
 static uae_u32 randseed;
 static int oldhcounter;
 
-uae_u32 uaesrand (uae_u32 seed)
+static uae_u32 xorshiftstate = 1;
+static uae_u32 xorshift32(void)
+{
+       uae_u32 x = xorshiftstate;
+       x ^= x << 13;
+       x ^= x >> 17;
+       x ^= x << 5;
+       xorshiftstate = x;
+       return xorshiftstate;
+}
+
+uae_u32 uaesrand(uae_u32 seed)
 {
        oldhcounter = -1;
        randseed = seed;
-       //randseed = 0x12345678;
-       //write_log (_T("seed=%08x\n"), randseed);
        return randseed;
 }
-uae_u32 uaerand (void)
+uae_u32 uaerand(void)
 {
        if (oldhcounter != hsync_counter) {
-               srand (hsync_counter ^ randseed);
+               xorshiftstate = (hsync_counter ^ randseed) | 1;
                oldhcounter = hsync_counter;
        }
-       uae_u32 r = rand ();
-       //write_log (_T("rand=%08x\n"), r);
+       uae_u32 r = xorshift32();
        return r;
 }
-uae_u32 uaerandgetseed (void)
+uae_u32 uaerandgetseed(void)
 {
        return randseed;
 }