matter.c

Cross-platform minimalist libc
git clone git://git.finwo.net/lib/matter.c
Log | Files | Refs | README | LICENSE

commit 51db4d29384febdde2cbbade26b4a73beed0d764
parent 5d0c7b7fd05f0d0d976119a159c830eebfd255a7
Author: Yersa Nordman <finwo@pm.me>
Date:   Fri, 19 Jun 2020 14:16:14 +0200

Added prng/rand

Diffstat:
Ainclude/stdlib.h | 9+++++++++
Asrc/prng/rand.c | 13+++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/include/stdlib.h b/include/stdlib.h @@ -0,0 +1,9 @@ +#ifndef _STDLIB_H_ +#define _STDLIB_H_ + +#include <stdint.h> + +void srand(unsigned s); +int rand(void); + +#endif // _STDLIB_H_ diff --git a/src/prng/rand.c b/src/prng/rand.c @@ -0,0 +1,13 @@ +#include <stdlib.h> +#include <stdint.h> + +static uint64_t seed; + +void srand(unsigned s) { + seed = s-1; +} + +int rand(void) { + seed = 6364136223846793005ULL*seed + 1; + return seed>>33; +}