driver/random: linear congruential

This commit is contained in:
Edgaru089 2021-11-07 01:29:07 +08:00
parent 763c34c8de
commit bd347df5d5
2 changed files with 32 additions and 0 deletions

15
driver/random/random.c Normal file
View File

@ -0,0 +1,15 @@
#include "random.h"
// glibc defaults
static const uint32_t a = 1103515245, c = 12345, m = 2147483648;
static uint32_t v = 1;
void random_Seed(uint32_t seed) {
v = seed;
}
uint32_t random_Rand() {
return v = (uint32_t)(((uint64_t)v * a + c) % m);
}

17
driver/random/random.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void random_Seed(uint32_t seed);
uint32_t random_Rand();
#ifdef __cplusplus
}
#endif