Files
mango/util/random.c
Max Wash 6019c9307d kernel: separate headers into kernel and user headers
all kernel headers have been moved from include/mango to include/kernel
and include definitions that are only relevant to kernel-space.

any definitions that are relevant to both kernel- and user-space
(i.e. type definitions, syscall IDs) have been moved to
include/mango within libmango.
2026-02-19 18:54:48 +00:00

37 lines
651 B
C

#include <kernel/util.h>
static unsigned int random_seed = 53455346;
bool fill_random(void *p, unsigned int size)
{
unsigned char *buffer = p;
if (!buffer || !size) {
return false;
}
for (uint32_t i = 0; i < size; i++) {
uint32_t next = random_seed;
uint32_t result;
next *= 1103515245;
next += 12345;
result = (uint32_t)(next / 65536) % 2048;
next *= 1103515245;
next += 12345;
result <<= 10;
result ^= (uint32_t)(next / 65536) % 1024;
next *= 1103515245;
next += 12345;
result <<= 10;
result ^= (uint32_t)(next / 65536) % 1024;
random_seed = next;
buffer[i] = (uint8_t)(result % 256);
}
return true;
}