xyyd-fatfox/src/utils/tool.ts

25 lines
718 B
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;
}