Added random number generator

This commit is contained in:
Alex 2022-10-27 03:05:34 +03:00
parent 0a2d3db946
commit ce7997a6ea
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 41 additions and 0 deletions

27
Core/Random.cpp Normal file
View File

@ -0,0 +1,27 @@
#include <rand.hpp>
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; }
}

14
include/rand.hpp Normal file
View File

@ -0,0 +1,14 @@
#ifndef __FENNIX_KERNEL_RANDOM_H__
#define __FENNIX_KERNEL_RANDOM_H__
#include <types.h>
namespace Random
{
uint16_t rand16();
uint32_t rand32();
uint64_t rand64();
void changeseed(uint64_t CustomSeed);
}
#endif // !__FENNIX_KERNEL_RANDOM_H__