Skip to content

Instantly share code, notes, and snippets.

@sdesalas
Last active November 15, 2018 20:59
Show Gist options
  • Select an option

  • Save sdesalas/10a316504cdd62399c353b391ff57757 to your computer and use it in GitHub Desktop.

Select an option

Save sdesalas/10a316504cdd62399c353b391ff57757 to your computer and use it in GitHub Desktop.
Base56 random character generation.
// Thanks to https://github.com/evanx/secret-base56
const letters24 = 'ABCDEFGHJKLMNPQRSTUVWXYZ'; // exclude I and O since too similar to 0 and 1
const digits8 = '23456789'; // omit 0 and 1 to avoid potential confusion with O and I (and perhaps 'l')
const charset = [digits8, letters24, letters24.toLowerCase()].join('');
module.exports = length => Array(length)
.fill()
.map(() => charset[Math.floor(Math.random() * 56)])
.join('');
@sdesalas

Copy link
Copy Markdown
Author

Usage:

const base56 = require('./base56');

console.log(`Public Address: 3${base56(33)}`); // Random Bitcoin address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment