Stm32 uses the rand () function to generate random numbers, and in OS Programming, Srand () random seeds are set, in fact, the random seed is the value of time (), because the value is different, so each random number is different.
Then we need to simulate such a random seed in the stm32.
1--can take ADC sampling values and must be an empty foot (no GND&VCC)
2--can use the timer's count value
Upload part of the code
/* You
must refresh the seed each time. The random number will not be the same each time
Srand () in #include "Stdlib.h"
rand () in #include "time.h"
* * srand
(timer_count_value); Random seed timer_count_value is the counting value of the timer,
num = rand ()% 128; Generates a random integer within 0-128,
printf ("<<---os_run:%d--->>\r\n", num);
Print results
<<---os_run:0--->>
<<---os_run:106--->>
<<---os_run:84--->>
<<---os_run:62--->>
<<---os_run:40--->>
<<---os_run:18--->>
<<---os_run:124--->>
<<---os_run:29--->>
<<---os_run:7--->>
<<---os_run:113--->>
<<---os_run:17--->>
<<---os_run:123--->>
<<---os_run:28--->>
<<---os_run:6--->>
<<---os_run:57--->>
<<---os_run:35--->>