Get unlimited public & private packages + team-based management with npm Teams.Learn more »


1.1.1 • Public • Published


Build Status License: GPL v3

Easy random is a bunch of simple random functions that I've gotten sick of rewriting in basically every npm package. No one likes dependencies so this doesn't have any. Well okay there are 3 dev dependencies for testing, but you don't have to install those in production, lucky you.


Readme's always have installation instructions so why would this one be any different.

$ npm install @remibutler/easyrandom

If you want to use this in production, and you should because it's better than your package, use the --production arg so you wont get any dev-dependencies installed.

$ npm ci @remibutler/easyrandom --production


Testing is done with:

This is simply because they're both very easy to use and hyper obvious, also they're basically mocha and chai, wait why don't we just use mo-

$ npm ci
$ npm test


const easyRandom = require('@remibutler/easyrandom');
const coin = easyRandom.flipACoin();

Full list of functions and their expected returns, there are jsdocs but you might wanna use runkit on npmjs so... here ya go!


Returns true or false randomly

easyRandom.flipACoin() // true or false

.getBetween(min, max)

Returns a psuedorandom positive whole number between a minium and maximum inclusive, parses input and shortcuts if the inputs are equal or the maximum is 0. If ether input is not parseable it will return 0.

easyRandom.getBetween(1, 6) // returns a whole number from 1 to 6


Returns a pseudorandom whole number between 0 and 100 inclusive

easyRandom.getPercent() // returns a whole number from 0 to 100


Returns a psuedorandom whole number between 0 and your maximum inclusive, it parses input and shortcuts if the input is 0, it will happily explode if you pass a number that's too big. If input is not parseable it will return 0.

easyRandom.getMax(200) // returns a whole number from 0 to 200

.getString(length (optional))

Returns a pseudorandom alphanumeric string of optional length, default length is 7. Returns empty string for 0 length.

easyRandom.getString(20) // returns a random alphanumeric string of 20 characters

.getStringNonNumeric(length (optional))

Returns a pseudorandom alpha string of optional length, default length is 7. Returns empty string for 0 length.

easyRandom.getStringNonNumeric(20) // returns a random alpha string of 20 characters

.getStringWithCustomCharacterSet(length (optional), characterset (optional))

Returns a string inside a custom character set of optional length, defaults to alphanumeric and length of 7. Returns empty string for 0 length.

easyRandom.getStringWithCustomCharacterSet(20, 'YOURFACE') // returns a random string from characterset provided of 20 characters


This is functionality i need to shamelessly steal add.


Returns a pseudorandom date.

.getDateBetween(minimum, maximum)

Returns a date between two dates, accepts two date objects, returns today if minimum is larger than maximum or if either isn't a date.


npm i @remibutler/easyrandom

DownloadsWeekly Downloads






Unpacked Size

49.1 kB

Total Files


Last publish


  • avatar