Files
ksOS/Kernel/Include/Lib/Rand.h
T
karina b519e69fbd feat(panic): funMessages in panic
feat(rand): also implemented rand
2026-04-30 13:10:07 +04:00

19 lines
444 B
C

#pragma once
#include <Types.h>
#include <Arch/Timer.h>
enum {
kRandSeed = 0x9E3779B97F4A7C15ULL,
kRandMultiplier = 0xBF58476D1CE4E5B9ULL,
kRandIncrement = 0x94D049BB133111EBULL,
};
static inline UInt64 Rand() {
static _Atomic UInt64 sequence = 0;
UInt64 z = (TimerGetCounter() + kRandSeed + (++sequence));
z = (z ^ (z >> 30)) * kRandMultiplier;
z = (z ^ (z >> 27)) * kRandIncrement;
return z ^ (z >> 31);
}