I make stuff

A somewhat better random generator

rand() sucks, and dealing with its wonky srand() is a drag. I wrote a simple ranged random number generator, it is part of my C math library header “Emaths”, it uses Xorshift shift-register method, here's the code:


      struct RandState{
          uint64_t seed;
          bool initialized = false;
      };
      RandState RANDSTATE;
       
      uint64_t rand_XOR(){
          if (!RANDSTATE.initialized){
              RANDSTATE.seed = time(NULL);
              RANDSTATE.initialized = true;
          }
          uint64_t x = RANDSTATE.seed;
          x ^= x << 9;
          x ^= x >> 5;
          x ^= x << 15;
          return RANDSTATE.seed = x;
      }
      int rand_range(int min, int max){
          return min + rand_XOR() % (max - min + 1);
      }