Last active
June 13, 2018 13:31
-
-
Save jasp402/0b6cfcb5c7ac4be4c9b321b68aafd0ea to your computer and use it in GitHub Desktop.
JavaScript - Generar Token aleatorio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//VERSION 1 | |
const rand=()=>Math.random(0).toString(36).substr(2); | |
const token=(length)=>(rand()+rand()+rand()+rand()).substr(0,length); | |
console.log(token(10)); | |
//VERSION 2 | |
function generateToken(length){ | |
let rand=()=>Math.random(0).toString(36).substr(2); | |
return (rand()+rand()+rand()+rand()).substr(0,length) | |
} | |
console.log(generateToken(40)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment