Electronic – Setting RNG (Random Number Generator) boundries

stm32

I am learning STM32F4 board. I want to get number between 0-15 using RNG. I can`t set boundaries to get that values.

Is there someone who has experienced with RNG or Can help me?

Best Answer

If you need an int use int bla = RNG_DR % 14 + 1 (yields a number between 0 and 15 (not including 0 and 15)); RNG_DR is the Data register of the RNG. You will need to check for the data ready flag to get valid values.

If you need something else, please specify :)