js-random-urn-draw

A simple js-class to put an array into an urn and draw random items from it - with or without replacement.

Usage no npm install needed!

<script type="module">
  import jsRandomUrnDraw from 'https://cdn.skypack.dev/js-random-urn-draw';
</script>

README

JS Random Urn Draw

npm GitHub Snyk Vulnerabilities for npm package npm npm Tests

A simple js-class to put an array into an urn and draw random items from it - with or without replacement.

Installation

Download this project via Github and add it manually to your project or install the JSON File Storage npm / yarn package:

npm i js-random-urn-draw / yarn add js-random-urn-draw

How to Use / API


const Urn = require('js-random-urn-draw'); // adjust the require path, if not installed via npm/yarn


const items = ["🍏", "🍒", "🍌"];


// urn WITH replacement
const urn = new Urn(items);

urn.drawOne(); // "🍌"
urn.draw(5); // ["🍒", "🍏", "🍒", "🍌", "🍌"]

urn.shake(); // ["🍌", "🍏", "🍒"]


// urn WITHOUT replacement
const urn_without = new Urn(items, false);

urn_without.drawOne(); // "🍌"
urn_without.content; // ["🍏", "🍒"]
urn_without.extractedContent; // ["🍌"]

urn.draw(5); //  ["🍏", "🍒"]
urn_without.content; // []
urn_without.extractedContent; // ["🍏", "🍒", "🍌"]

Donate

If you like the project and it saved you a while of coding, spend me a coffee (or all of your savings) to keep me motivated: paypal.me