Random Charts
A small library for the easy creation of random charts.
Setup
- Assumes node installed
- npm install
- npm run build (jshint, clean, babel, test)
Usage Examples
Note: Items in a chart can be just Strings or a deep object. (See tests in the charts folder.)
//Basic Chart (basic items selection = equal chance of all items);const items = "Item1" "Item2";const chart = ; //OR const chart = CreateChartForItems(items); (creates a random chart name for you.)const singleItem = chart;const sixItems = chart;
Example showing item selection with dice rolling. More than 1 die rolled produces a bell curve. 2d4 Bell curve from AnyDice
//Basic Chart with items selected by Rolling Dice (2d4 Bell curve)const diceItems = "2" "3" "4" "5" "6" "7" "8";const selectionStrategy2d4 = 2 4;const diceChart =
//chart result example
[
{
"index": 1,
"item": "Item2"
}
]
Example showing rolling a table that links to other tables.
RandomChartconst subTable = linked: false name: "A SubTable" items: "Chart2-A" "Chart2-B" "Chart2-C";const mainTable = name: "Some Linked Chart" items: "Chart1-1" "Chart1-2" "Chart1-3" linkedTable:subTablename description:"Roll on Subtable: " + subTablename; const randomSeedThatReturnsIndexOf3ToForceTestOfLinkedItem = 3; //get the linkedItem to demonstrate rolling into subtablesconst chart = mainTablename mainTableitems subTable randomSeedThatReturnsIndexOf3ToForceTestOfLinkedItem;const singleItem = chart; //
//Linked chart result example
[
{
index: 3,
item:
{
linkedTable: 'A SubTable',
description: 'Roll on Subtable: A SubTable'
},
subResult:
[
{
index: 2,
item: 'Chart2-C'
}
]
}
]