From d29dc4db7f3de1363dfd88b0e463e70099f5fd37 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 1 Mar 2014 13:33:01 +0200 Subject: [PATCH] Add RNG module --- src/{ => img}/imlib.c | 0 src/{ => img}/integral.c | 0 src/{ => img}/template.c | 0 src/rng.c | 19 +++++++++++++++++++ src/rng.h | 5 +++++ 5 files changed, 24 insertions(+) rename src/{ => img}/imlib.c (100%) rename src/{ => img}/integral.c (100%) rename src/{ => img}/template.c (100%) create mode 100644 src/rng.c create mode 100644 src/rng.h diff --git a/src/imlib.c b/src/img/imlib.c similarity index 100% rename from src/imlib.c rename to src/img/imlib.c diff --git a/src/integral.c b/src/img/integral.c similarity index 100% rename from src/integral.c rename to src/img/integral.c diff --git a/src/template.c b/src/img/template.c similarity index 100% rename from src/template.c rename to src/img/template.c diff --git a/src/rng.c b/src/rng.c new file mode 100644 index 000000000..069e12268 --- /dev/null +++ b/src/rng.c @@ -0,0 +1,19 @@ +#include +#include +#include "rng.h" + +void rng_init() +{ + RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); + RNG_Cmd(ENABLE); +} + +uint32_t rng_randint(uint32_t min, uint32_t max) +{ + uint32_t rand; + if (min==max) { + return 0; + } + rand = RNG_GetRandomNumber(); + return (rand%(max-min))+min; +} diff --git a/src/rng.h b/src/rng.h new file mode 100644 index 000000000..da39fee26 --- /dev/null +++ b/src/rng.h @@ -0,0 +1,5 @@ +#ifndef __RNG_H__ +#define __RNG_H__ +void rng_init(); +uint32_t rng_randint(uint32_t min, uint32_t max); +#endif /* __RNG_H__ */