parent
fbcbef02af
commit
86e9e77410
@ -0,0 +1,15 @@
|
||||
export type Hex = string
|
||||
|
||||
const hexGen = (len: number = 12): Hex => {
|
||||
const maxlen = 8
|
||||
const min = Math.pow(16, Math.min(len, maxlen) - 1)
|
||||
const max = Math.pow(16, Math.min(len, maxlen)) - 1
|
||||
const n = Math.floor(Math.random() * (max - min + 1)) + min
|
||||
let r = n.toString(16)
|
||||
while (r.length < len) {
|
||||
r = r + hexGen(len - maxlen)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
export default hexGen
|
Loading…
Reference in new issue