ch32hack/rand.c
2025-02-12 19:47:19 +01:00

22 lines
563 B
C

#include <stdint.h>
#include <stdint.h>
#define BUILD_SEED ((uint64_t)(__TIME__[0]) * (uint64_t)(__TIME__[1]) * \
(uint64_t)(__TIME__[3]) * (uint64_t)(__TIME__[4]) * \
(uint64_t)(__TIME__[6]) * (uint64_t)(__TIME__[7]))
static uint64_t seed = BUILD_SEED;
void sprand(uint64_t s) {
seed = s ? s : 1; // Ensure the seed is never 0
}
uint64_t prand() {
seed = seed * 6364136223846793005ULL + 1;
return seed;
}
uint64_t prand_range(uint64_t min, uint64_t max) {
return min + (prand() % (max - min + 1));
}