Files
ksOS/Kernel/Include/Lib/Rand.h
T
2026-05-03 13:05:55 +04:00

22 lines
519 B
C

// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 0xKSor
#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);
}