You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
384 B
16 lines
384 B
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
|