Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 16, 2021 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/f12df39ae8403067ed3b1e8f746d6ed9 to your computer and use it in GitHub Desktop.
Save parzibyte/f12df39ae8403067ed3b1e8f746d6ed9 to your computer and use it in GitHub Desktop.
const cadenaAleatoria = longitud => {
// Nota: no uses esta función para cosas criptográficamente seguras.
const banco = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let aleatoria = "";
for (let i = 0; i < longitud; i++) {
// Lee más sobre la elección del índice aleatorio en:
// https://parzibyte.me/blog/2021/11/30/elemento-aleatorio-arreglo-javascript/
aleatoria += banco.charAt(Math.floor(Math.random() * banco.length));
}
return aleatoria;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment