mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add RNG module
This commit is contained in:
parent
36bfe95829
commit
d29dc4db7f
19
src/rng.c
Normal file
19
src/rng.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include <stm32f4xx_rng.h>
|
||||
#include <stm32f4xx_rcc.h>
|
||||
#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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user