mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Added random number generator
This commit is contained in:
parent
0a2d3db946
commit
ce7997a6ea
27
Core/Random.cpp
Normal file
27
Core/Random.cpp
Normal 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
14
include/rand.hpp
Normal 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__
|
Loading…
x
Reference in New Issue
Block a user