Skip to content

Instantly share code, notes, and snippets.

@dvgamerr
Last active April 23, 2018 13:28
Show Gist options
  • Save dvgamerr/7fd5f0191dc567b8542b28206e486fbd to your computer and use it in GitHub Desktop.
Save dvgamerr/7fd5f0191dc567b8542b28206e486fbd to your computer and use it in GitHub Desktop.
let charType = () => {
let group = [ 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2 ]
return group[parseInt(Math.random() * group.length)]
}
let charASCII = t => parseInt(Math.random() * (t === 0 ? 9 : 25))
const randomString = l => {
l = l || 32
let result = ''
for (let i = 0; i < l; i++) {
let t = charType()
let n = charASCII(t)
result += t === 0 ? n.toString() : String.fromCharCode(t === 1 ? 97 + n : 65 + n)
}
return result
}
console.log('random:', randomString(16))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment