Badrand pseudo random number generator, emphasis on pseudo
This commit is contained in:
parent
edc082adcb
commit
4c96aac02c
4 changed files with 95 additions and 1 deletions
43
kern/libkern/badrand.h
Normal file
43
kern/libkern/badrand.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef BADRAND_H
|
||||
#define BADRAND_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* This is a PRNG for non-cryptographic use.
|
||||
*
|
||||
* See:
|
||||
* https://en.wikipedia.org/wiki/Linear_congruential_generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Sets the seed for the PRNG.
|
||||
*
|
||||
* @param s The specific seed value or zero. If zero is passed, it will call
|
||||
* rand_reseed().
|
||||
*/
|
||||
void sbadrand(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 badrand();
|
||||
|
||||
/**
|
||||
* @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 badrand_range(uint64_t min, uint64_t max);
|
||||
|
||||
#endif // BADRAND_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue