driver/random: linear congruential
This commit is contained in:
parent
763c34c8de
commit
bd347df5d5
15
driver/random/random.c
Normal file
15
driver/random/random.c
Normal 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
17
driver/random/random.h
Normal 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
|
Loading…
Reference in New Issue
Block a user