From ce7997a6ea6c018a561d923afccdcd09b9acd164 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 27 Oct 2022 03:05:34 +0300 Subject: [PATCH] Added random number generator --- Core/Random.cpp | 27 +++++++++++++++++++++++++++ include/rand.hpp | 14 ++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Core/Random.cpp create mode 100644 include/rand.hpp diff --git a/Core/Random.cpp b/Core/Random.cpp new file mode 100644 index 0000000..8e05863 --- /dev/null +++ b/Core/Random.cpp @@ -0,0 +1,27 @@ +#include + +namespace Random +{ + static uint64_t Seed = 0xdeadbeef; + + uint16_t rand16() + { + Seed = Seed * 1103515245 + 12345; + return (uint16_t)(Seed / 65536) % __UINT16_MAX__; + } + + uint32_t rand32() + { + Seed = Seed * 1103515245 + 12345; + return (uint32_t)(Seed / 65536) % __UINT32_MAX__; + } + + uint64_t rand64() + { + Seed = Seed * 1103515245 + 12345; + return (uint64_t)(Seed / 65536) % __UINT64_MAX__; + } + + void changeseed(uint64_t CustomSeed) { Seed = CustomSeed; } + +} \ No newline at end of file diff --git a/include/rand.hpp b/include/rand.hpp new file mode 100644 index 0000000..81cff9e --- /dev/null +++ b/include/rand.hpp @@ -0,0 +1,14 @@ +#ifndef __FENNIX_KERNEL_RANDOM_H__ +#define __FENNIX_KERNEL_RANDOM_H__ + +#include + +namespace Random +{ + uint16_t rand16(); + uint32_t rand32(); + uint64_t rand64(); + void changeseed(uint64_t CustomSeed); +} + +#endif // !__FENNIX_KERNEL_RANDOM_H__