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

@ededejr/randomly

v0.2.1

Published

A utility for generating random numbers very frequently.

Downloads

4

Readme

Randomly

A utility for generating lots of random numbers without being too tasking on the browser. Randomly accomplishes this by generating a set of random numbers on a given interval.

Subsequent requests for random numbers are served from the generated set instead of calling Math.random. In addition to getting random numbers, some useful methods have also been added around random numbers.

Motivation

Working on several generative art projects inspired the need for a common utility which would handle very frequent calls to Math.random as well as other provided methods which involve using random numbers.

Benchmarks

Why not just use Math.random? Depending on how many numbers are being generated Randomly tends to be more performant as frequency increases. The following chart shows their comparison. You can view how this was measured in the benchmark.ts file.

Usage

import Randomly from '@ededejr/randomly';

const randomly = new Randomly();

Getting a random number

randomly.get(); // Returns a number between 0 and 1

Compare a random number using a predicate

randomly.compare((value) => Math.floor(value * 1000) > 500);

Check if a random number is less than a threshold

randomly.lt(0.2);

Check if a random number is greater than a threshold

randomly.gt(0.2);

Check if a random number is between an upper and lower bound

randomly.between(0.2, 0.6);

Decide between two values

randomly.decide('Option A', 'Option B');

Get a Radom number between 0 and a given value

randomly.sample(100);

Controlling the timer

If you would like to pause the interval:

randomly.stopTimer();

Starting it up again:

randomly.startTimer();

Customizing the interval or store size

import Randomly from '@ededejr/randomly';

const randomly = new Randomly({
	refreshInterval: 5000, // refresh random number store every 5 seconds
	storeSize: 100, // keep a store of a 100 random numbers
});