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

34 lines
998 B
C

#pragma once
#include <stdint.h>
/**
* @brief Sets the seed for the custom random number generator.
*
* This function initializes the seed value used by rand_custom().
* Providing the same seed will produce the same sequence of random numbers.
*
* @param s The seed value (must be nonzero for best results).
*/
void sprand(uint64_t s);
/**
* @brief Generates a pseudo-random 64-bit number.
*
* Uses a simple Linear Congruential Generator (LCG) to produce
* a sequence of pseudo-random numbers.
*
* @return A pseudo-random 64-bit unsigned integer.
*/
uint64_t prand();
/**
* @brief Generates a random number within a specified range.
*
* Produces a random number in the inclusive range [min, max].
* Ensures uniform distribution by applying a modulo operation.
*
* @param min The lower bound of the range (inclusive).
* @param max The upper bound of the range (inclusive).
* @return A random number between min and max.
*/
uint64_t prand_range(uint64_t min, uint64_t max);