This code contains the game Starship designed for the STM32F429i-DISC1 board. It requires a keyboard to play.
Dependencies: Starship LCD_DISCO_F429ZI USBHost mbed
Diff: RandomVar.c
- Revision:
- 1:527a11035e0b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RandomVar.c Fri Nov 17 02:23:33 2017 +0000 @@ -0,0 +1,13 @@ +#include "RandomVar.h" +int8_t probabilityOfSuccess(float prob) +{ + int randInt = rand(); + float maxInt = RAND_MAX*prob; + return randInt<maxInt ? 1 : 0; +} +int randomInt(int min,int max) +{ + int range = max - min + 1; + int result = (int)((rand()/((float)RAND_MAX))*range) + min; + return result==max+1 ? max : result; +} \ No newline at end of file