2024-10-23 14:57:27 +08:00
|
|
|
/**
|
|
|
|
|
* 生成随机数
|
|
|
|
|
* @param min 最小值
|
|
|
|
|
* @param max 最大值
|
|
|
|
|
* @returns 随机数
|
|
|
|
|
*/
|
|
|
|
|
export function randomNum(min: number, max: number) {
|
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
2024-10-28 18:51:13 +08:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 生成一个长度在 0 到 n 之间的随机字符串。
|
|
|
|
|
* @param n 最大字符串长度。
|
|
|
|
|
* @returns 随机生成的字符串。
|
|
|
|
|
*/
|
|
|
|
|
export function generateRandomString(n: number): string {
|
|
|
|
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
|
const length = Math.floor(Math.random() * (n + 1));
|
|
|
|
|
let result = '';
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
|
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2024-11-04 14:25:11 +08:00
|
|
|
}
|