initial commit

This commit is contained in:
Alireza Ahmadi
2024-02-13 01:17:03 +01:00
commit f40b27fd8b
136 changed files with 16023 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
const seq = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
const RandomUtil = {
randomIntRange(min: number, max: number): number {
return parseInt((Math.random() * (max - min) + min).toString(), 10)
},
randomInt(n: number) {
return this.randomIntRange(0, n)
},
randomSeq(count: number): string {
let str = ''
for (let i = 0; i < count; ++i) {
str += seq[this.randomInt(62)]
}
return str
},
randomLowerAndNum(count: number): string {
let str = ''
for (let i = 0; i < count; ++i) {
str += seq[this.randomInt(36)]
}
return str
},
randomUUID(): string {
let d = new Date().getTime()
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
let r = (d + Math.random() * 16) % 16 | 0
d = Math.floor(d / 16)
return (c === 'x' ? r : (r & 0x7 | 0x8)).toString(16)
})
},
randomShadowsocksPassword(n: number): string {
const array = new Uint8Array(n)
window.crypto.getRandomValues(array)
return btoa(String.fromCharCode(...array))
},
randomShortId(): string[] {
let shortIds = ['','','','']
for (var ii = 0; ii < 4; ii++) {
for (var jj = 0; jj < this.randomInt(8); jj++){
let randomNum = this.randomInt(256)
shortIds[ii] += ('0' + randomNum.toString(16)).slice(-2)
}
}
return shortIds
}
}
export default RandomUtil