mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
framework: refactor randomstring (#1199)
This commit is contained in:
1 parent
df00fa0de5
commit
409af9270b
1 file changed
+3
-1
@@ -1,3 +1,5 @@
|
||||
import { randomInt } from 'node:crypto';
|
||||
|
||||
declare global {
|
||||
interface String {
|
||||
format: (...args: Array<any>) => string;
|
||||
@@ -13,7 +15,7 @@ const defaultDict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567
|
||||
|
||||
export function randomstring(digit = 32, dict = defaultDict) {
|
||||
let str = '';
|
||||
for (let i = 1; i <= digit; i++) str += dict[Math.floor(Math.random() * dict.length)];
|
||||
for (let i = 1; i <= digit; i++) str += dict[randomInt(dict.length)];
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user