/*############################################################# Program Name : ex2_rng_dices Author : Grant Phillips Date Modified : 08/02/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : This example will demonstrate the STM32F4_RNG class library to simulate the throw of two dices. Requirements : * STM32F4-Discovery Board Circuit : * A wire link between PB3 and pin6 of the SWD connector (CN2) as explained in the SWV examples section ##############################################################*/ #include "mbed.h" #include "STM32F4_RNG.h" #include "SWO.h" STM32F4_RNG rnd; //create a STM32F4_RNG object SWO_Channel SWO; int main() { unsigned long num; int dice1, dice2; while(1) { num = rnd.Get(); //get the next 32-bit random number and store in num dice1 = num % 6 + 1; //convert the 32-bit number to an integer with the formula: x = RNG 32-bit value % MAX_REQUIRED + MIN_REQUIRED num = rnd.Get(); //get the next 32-bit random number and store in num dice2 = num % 6 + 1; //convert the 32-bit number to an integer with the formula: x = RNG 32-bit value % MAX_REQUIRED + MIN_REQUIRED SWO.printf("DICE1: %d DICE2: %d\n", dice1, dice2); wait(1.0); } }