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

randomized-js

v0.5.2

Published

Small library for random/seeded functions

Downloads

3

Readme

Randomized.js

Randomized.js is simple javascript library, that can makes Randomizing and Seeding easier.

Download

You can download randomized-js with npm and require it:

npm install randomized-js
const Random = require('randomized-js')

Or you can just import it with ES6 modules:

import Random from 'https://unpkg.com/randomized-js/randomized.js'

Usage

Main methods for creating random numbers are Random.number(min,max,seed?) and Random.random(seed?) You can also use Random.pick(arr,seed) and Random.randomize(arr,seed) to pick/randomize your array (examples below);

//Random.number(min,max,seed?/floor?,floor?);
Random.number(1, 12, "Hi") // Alway 2
Random.random("Hello") // Always 0.6962755533213519

Random.pick([1,2,3,4,5],"123") // Returns 5
Random.randomize([1,2,3,4],"o.O") // returns [1, 3, 4, 2]

You can also use new Random(seed?) constructor to create instance of Random. If you dont provide seed, it will just use Math.random() to generate numbers.

const rnd = new Random("Hello World")
rnd.random() // Always 0.5423943877054241
//Usage: rnd.next(min,max,floor?)
rnd.next(0,9,false) // Always 7.731296254855902
rnd.next(0,9,true) // Always 3
rnd.reSeed("Random.js"); // Reseeds to "Random.js"
rnd.next(0,9) // Always 8

Everytime you run rnd.next(), the next generated value will be different! (example below)

const rnd = new Random("See!");
rnd.next(0,10); //Always returns 9
rnd.next(0,10); //Always returns 8
rnd.next(0,10); //Always returns 0

Every time you run rnd.random(seed) or rnd.next(min,max), next random number will be changed If you want generate one random number with/without seed you can use static function Random.number(seed) or Random.number(seed):

//Usage: Random.number(min,max,seed?/floo?r,floor?)
Random.number(1,2) // returns 1 or 2
Random.number(1) // returns 0 or 1
Random.number(1,9,"Seed") // Always returns 2
Random.number(6,9,"", false) // returns a number from 6 to 9 with decimal numbers
Random.number(6,9, false) // again returns a number from 6 to 9 with decimal numbers
Random.number(10,20,"Weird huh",false) // Always 15.03660798224236
Random.number(2,18,"Weird huh",false) // Always 9.783848699829104
//As you can see, even with the same seed the number is different

//Usage Random.random(seed?)
Random.random("Out of ideas") // Always 0.8273460546070028
Random.random() // Random number from 0-1

There are two more static functions! Random.pick(array) which picks a random item from array (It also supports string) and Random.randomize(array) which randomizes array, string or number Both supports seeding

// Usage Random.pick(input,seed?)
Random.pick([1,2,3]) // Returns 1 , 2 or 3
Random.pick([1,2,3],"123") // Returns 3
Random.pick([1,2,3,4,5],"123") // Returns 5

Random.pick("Hello World") // Returns h, e, l, o, w, r or d
Random.pick("Hello World","Hi") // Returns e

//Usage Random.pick(input,seed?,rolls?)
Random.randomize([1,2,3,4,5,6],"o.O") // returns [2, 1, 4, 5, 6, 3]
Random.randomize([1,2,3,4],"o.O") // returns [1, 3, 4, 2]
Random.randomize([2,6,8,1,6,4]) // returns randomized array ex.