亦可将此方法与实时时钟结合使用,即:
HAL_RTC_GetTime(&hrtc, &time_info, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &date_info, RTC_FORMAT_BIN);
printf("当前时间:%2d:%2d:%2d", time_info.Hours, time_info.Minutes, time_info.Seconds);
HAL_TIM_Base_Start(&htim3);
srand(time_info.Hours+time_info.Minutes+time_info.Seconds+__HAL_TIM_GET_COUNTER(&htim3));//随机数种子设置
#define RANDOM_MAX 65535 //随机数最大值
#define RANDOM_MIN 0 //随机数最小值
uint32_t random_value;
random_value = rand() % (RANDOM_MAX + 1 - RANDOM_MIN) + RANDOM_MIN;//随机数生成
printf(" 当前随机数为:%d\r\n", random_value);
|