npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rand64-pmb

v0.1.0

Published

Waste less randomness when generating random sequences of the first 64 characters of your alphabet.

Downloads

3

Readme

rand64-pmb

Waste less randomness when generating random sequences of the first 64 characters of your alphabet.

A lot of modules out there just modulo(random, alphabet.length), which wastes a lot of randomness to duplicate choices. Especially in cases where the to-be-used prefix of your alphabet is at most 36 characters long, or (in this module's case) is a square number, you can generate digits more easily and less wasteful using JavaScript numbers' .toString() method, and keep unused digits for later.

On my development machine, one random number usually produces 8 to 9 random characters, so this module drains my randomness pool a low slower than a naive implementation.

Usage

For more details, see the test/ directory.

var rand64 = require('rand64-pmb'), urlSafe;
function demo(func, args) { console.log(repeat(4, func, args)); }

demo(rand64, [ /* no arguments */ ]);
// example output: [ 'HqWLD2En', 'qCqip+1T', 'em/kSMNZ', 'KkkPsb9U' ]

demo(rand64, [ 3 ]);
// ex. [ '+ip', '9qx', 'gOz', 'Fb0' ]

urlSafe = rand64.custom({ charset: rand64.charsets.url, len: 12 });
demo(urlSafe, []);
// ex. [ '9qTssF8_qUIY', 'LU-zHa_0y1rZ', 'UVCFa2d2ljPy', 'q9QF9DDNjW-7' ]

// If the alphabet is too short, the base64 alphabet is appended, so these
// parameters are effectively the same as in the previous exmaple:
urlSafe = rand64.custom({ charset: '-_' });
demo(urlSafe, [ 12 ]);
// ex. [ 'isKpZpAaNM-I', 'h-PqEoSa_uki', '0-lmKvH1WFt-', 'Qqkwley8y1KK' ]

License

ISC