Generate repeatable random data in JS
Inspired by Faker.js Uses slightly modified Alea PRNG
For the server, install Blarney via npm.
npm install Blarney
For the browser, download Blarney.js, and include it as a script tag.
<script src="Blarney.js"></script>
<script>
var ns = new Blarney();
ns.integer(); // Random integer between 0 and 2^32
</script>
To create a new Blarney instance, do var ns = new Blarney();
. You can pass any number of arbitrary arguments to the Blarney()
constructor to be used as seed data. If you don't pass anything, it will just use the default.
If you want to reset the seed of an instance you already have, call ns.sow()
and pass in the seed data you want to use. The constructor calls sow()
internally on instantiation.
integer()
- returns a random integer between 0 and 2^32frac()
- returns a random real number between 0 and 1real()
- returns a random real number between 0 and 2^32integerInRange(min, max)
- returns a random integer between min and maxrealInRange(min, max)
- returns a random real number between min and maxnormal()
- returns a random real number between -1 and 1
uuid()
- returns a valid v4 UUID hex stringpick(array)
- returns a random member ofarray
weightedPick(array)
- returns a random member ofarray
, favoring the earlier entriestimestamp(min, max)
- returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified
word()
- returns a random word of lipsumwords(n)
- returnsn
random words of lipsum, 3 if not specifiedsentence()
- returns a random lipsum sentencesentences(n)
- returnsn
random lipsum sentences, 3 if not specified
gender()
- returns 'male' or 'female'firstName(gender)
- returns a random common first name, gender is optionallastName()
- returns a random common last namename(gender)
- returns a random first and last name, gender is optionalportrait(gender)
- returns an object containing Flickr short URLs for four images. Keys aresmallSquare
,largeSquare
,thumbnail
, andsmall
. The photos are from GregPC's 1000faces1 set on Flickr. Special thanks to him for doing all the hard work and allowing us to benefit from it!jobTitle()
- returns a random job titleemail()
- returns a random email address
buzzPhrase()
- returns a random web 2.0 business plan...domain()
- returns a random domain name
Do whatever you want with this code. The consequences of your actions are your own responsibility.