git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

Core/random.c

      1 #include "random.h"
      2 #include <time.h>
      3 
      4 static uint64_t seed;
      5 static bool enabled = true;
      6 
      7 uint8_t GB_random(void)
      8 {
      9     if (!enabled) return 0;
     10     
     11     seed *= 0x27BB2EE687B0B0FDL;
     12     seed += 0xB504F32D;
     13     return seed >> 56;
     14 }
     15 
     16 uint32_t GB_random32(void)
     17 {
     18     GB_random();
     19     return seed >> 32;
     20 }
     21 
     22 void GB_random_seed(uint64_t new_seed)
     23 {
     24     seed = new_seed;
     25 }
     26 
     27 void GB_random_set_enabled(bool enable)
     28 {
     29     enabled = enable;
     30 }
     31 
     32 static void __attribute__((constructor)) init_seed(void)
     33 {
     34     seed = time(NULL);
     35     for (unsigned i = 64; i--;) {
     36         GB_random();
     37     }
     38 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.