Skip to content

Instantly share code, notes, and snippets.

@nelsondev19
Created July 26, 2021 04:22
Show Gist options
  • Save nelsondev19/ab05525942f7f97b4501eef12d2dc7c7 to your computer and use it in GitHub Desktop.
Save nelsondev19/ab05525942f7f97b4501eef12d2dc7c7 to your computer and use it in GitHub Desktop.
Ejemplo de como generar text random con JavaScript
export const generateCode = (nombre)=> {
//OBTENIENDO PARTE DEL NOMBRE DE LA PERSONA
var primerNombre = ""
var arrayNombre = nombre.split(" ");
var nombreConEspacios = arrayNombre.length;
if (nombreConEspacios > 1) {
primerNombre = arrayNombre[0]
}
const abecedario = ["ww","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","$","&","#","@"];
const numeros = ["0","1","2","3","4","5","6","7","8","9"]
const letrasGenerados = abecedario[Math.round(Math.random() * (abecedario.length - 1) + 1)] + abecedario[Math.round(Math.random() * (abecedario.length - 1) + 1)] + abecedario[Math.round(Math.random() * (abecedario.length - 1) + 1)]
const numerosGenerados = Math.round(Math.random() * (numeros.length - 1) + 1)
const codigoGenerado = letrasGenerados + numerosGenerados
return primerNombre + codigoGenerado
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment