xyyd-fatfox/src/utils/tool.ts

40 lines
1.2 KiB
TypeScript
Raw Normal View History

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;
}
/**
* 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:45:25 +08:00
}
/**
* :
* @param seconds -
* @returns MM:SS
*/
export function formatSeconds(seconds: number): string {
// 计算分钟数
const minutes = Math.floor(seconds / 60);
// 计算剩余的秒数
const remainingSeconds = seconds % 60;
// 返回格式化后的字符串,确保分钟和秒数都是两位数
return `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;
}