fix: improve timeout prompt randomization

This commit is contained in:
chenjintao
2026-09-22 11:42:04 +08:00
parent 64fdeb9aaa
commit d6c31ffe31
@@ -21,6 +21,7 @@
#include "ql_ping.h"
#include "ql_nw.h"
#include "ql_atcmd.h"
#include "ql_platform.h"
#include "layer3.h"
#include "ql_uart.h"
#include "hal_api.h"
@@ -195,7 +196,10 @@ static void remove_underscores(char *str) {
*/
static int randomize_tts_error_url(char *url, size_t url_size)
{
static uint32_t random_sequence = 0;
static unsigned int last_random_index = 10;
char *file_name;
uint32_t random_value;
unsigned int random_index;
int written;
@@ -211,7 +215,21 @@ static int randomize_tts_error_url(char *url, size_t url_size)
return 0;
}
random_index = hal_os_get_rand() % 10;
/*
* 某些设备上硬件随机接口可能持续返回 0,因此混合伪随机数、系统 tick
* 和递增序列;若仍与上一次相同,则向后偏移,避免连续重复播放。
*/
random_sequence++;
random_value = hal_os_get_rand();
random_value ^= ql_pseudo_random_number();
random_value ^= ql_rtos_get_systicks();
random_value ^= random_sequence * 0x9E3779B9U;
random_index = random_value % 10;
if(random_index == last_random_index){
random_index = (random_index + 1 + (random_sequence % 9)) % 10;
}
last_random_index = random_index;
written = snprintf(url, url_size, CLOUD_TTS_ERROR_URL_FORMAT, random_index);
if(written < 0 || (size_t)written >= url_size){
printf("random tts error url buffer too small\n");