Skip to the content

Korokoroコロコロ

Roll mixed dice or type notation, compare exact probabilities, keep a history and replay seeded rolls.

Korokoro describes something small rolling in Japanese. About the name

Contents

Reference

Rolls and exact odds

import { … } from "@johnmorrisdotca/korokoro";

101.0 kB minified and gzipped, with everything it imports (measured with esbuild)

Korokoro コロコロ: fair dice, exact odds, and a history that remembers.

The core is plain functions over plain data, with no dependency and no DOM: roll, read the odds, keep a history and summarise it. The tap-to-roll tray is mountRoller in ./ui/mount.ts, exported here too.

Exports

NameKindWhat it is
addToHistoryfunctionAdd a roll to the end, oldest dropped past the limit.
asChancefunctionA fraction as a number, for showing.
canHoldfunctionWhether some dice of a roll can be held while the rest are thrown again: plain dice only, none rerolled, exploding, kept or dropped, counted, raised, lowered or sorted.
chanceAnyAtLeastfunctionThe chance that at least one of several throws of a roll reaches a target: a set of six ability scores holding at least one 16, say.
chanceAtLeastfunctionThe chance of this total or more: "what do I need to beat a DC of 15".
chanceAtMostfunctionThe chance of this total or less.
chanceExactlyfunctionThe chance of exactly this total.
chancesOffunctionThe chance of each face of one die of a group, from its lowest face up.
checkMathfunctionWhether a formula can be used with kinds of dice whose totals run over these ranges: the problem, or null when there is none.
checkNotationfunctionA spec from notation, or which part of the text was refused and why.
chinchirorinHandWithinfunctionThe chance that three dice make a chinchirorin hand within a number of throws: each throw makes one half the time, so three come to 7 in 8.
chiSquareTailfunctionThe upper tail of a chi-square distribution: the chance that a fair die strays at least this far.
cliLanguagefunctionThe language the command line speaks: --lang, or the environment's, or the system's; Japanese for ja…, English for anything else.
CliResulttypeWhat the command line came to.
CliSurroundingstypeWhat the command line is run in.
ClothtypeA cloth's name.
clothVarsfunctionA cloth as the tray's CSS variables; nothing for a name that is not a cloth, so the tray keeps its own.
ComparetypeA number a die is compared with: at a face (=), at or below it (<=), at or above it (>=), or anything but it (<>).
compareTextfunctionA comparison as notation writes it: >=8, =1, <>3.
countsSuccessesfunctionWhether a kind of dice is counted for successes, not added up.
crapsPassfunctionThe chance that a craps shooter passes: a natural on the come-out, or a point that comes again before a seven.
createRollSoundfunctionThe tray's sound for one window.
cryptoSourcefunctionThe platform's cryptographic generator, buffered so a roll of ten dice is one call.
CSV_COLUMNSconstantThe columns of the CSV export, in order.
csvCellfunctionOne cell of CSV.
CustomFacetypeOne face of a custom die: what it says, what it is worth in a total if it is worth anything, and a colour for it.
customFacesfunctionA custom die's faces, checked: the faces as given if every one is sound, or undefined.
decodeDiceWarfunctionText read back into the game it records, every move played again through the rules, so that what comes back is exactly the game those moves make.
DEFAULT_SPECconstantThe dice a tray shows when nothing else is asked for: 2d6.
DICE_WAR_LIMITSconstantWhat a table may be set up with.
diceCountfunctionHow many dice a roll asks for, over all its kinds.
DiceGrouptypeSome dice of one kind, with their own rules: the 2d20kh1 of 2d20kh1+1d4.
diceOffunctionThe dice of a roll: as recorded, or worked out from its faces for a roll made by hand or by an older version.
DiceSettypeA set of dice with a name: a roll somebody wants to find again, such as "Longsword" for 1d8+3 or "Skirmish" for 2d[Hit=1,Miss=0,Miss=0].
diceTextfunctionThe dice of a roll as plain text, in the order thrown: 6 4 2 (1).
DiceWarChancestypeWhat a total is worth against the other players' totals in one throw.
diceWarComputerFacesfunctionA computer's dice for a throw: from the game's seed, the round, the war and the seat, so the same game always rolls the same.
DiceWarGametypeA game of Dice War: its table, seed and moves (what is kept), and what they make.
DiceWarGoaltypeHow a game is played to its end.
DiceWarMovetypeA move: the dice the people at the table rolled, by seat, such as { faces: { "0": [4] } }.
diceWarOddsfunctionThe exact odds of one throw of Dice War among players players, from the package's own odds for the dice: the chance the throw is settled at once and the chance of war, and, for a total you name, how it fares against everybody else's.
DiceWarOptionstypeWhat a game of Dice War is set up with.
diceWarOverfunctionWhether a game is over.
diceWarPeopleToRollfunctionThe seats whose dice a move must hand in now: the people among those who roll.
DiceWarRolltypeOne player's roll in a throw: their faces, and what they add up to.
diceWarSpecfunctionThe dice a game rolls, as a spec the rest of the package reads.
DiceWarThrowtypeOne throw of the table: everybody who had to roll, in seat order, the war it was in (0 for the round's first throw), the seats that tied for highest, and who took the stake: null where the throw was a tie and the war goes on, or the round was called off.
diceWarWinnersfunctionThe seats that won a game that is over: the player who reached the score, or the most points when the rounds ran out, shared where level.
DIE_SIDESconstantThe dice the tray offers as buttons: the polyhedral set, the thirty-sided die, and the percentile die.
DIE_SIZE_PXconstantThe pixels of each size.
DieHandletypeWhat mountDie hands back.
dieNamefunctionWhat one kind of die is called: d6, dF, a loaded d6{6:3}, a custom d[Yes,No,Maybe].
DieOptionstypeWhat a lone die is told when it is made.
dieOutcomesfunctionOne die of a kind worked through its own rules, before any keeping or dropping: the chance of each amount it adds to the total, from least up.
DieRolltypeOne die of a roll: the face it showed and what became of it.
DieSidestypeOne of the dice the tray has a button for.
DieSizetypeHow big the die is drawn: 48, 96 or 150 pixels across.
DieStatustypeOne die as it was thrown.
DistributiontypeExact odds for a spec, worked out rather than simulated: every total the dice can make and how likely it is.
distributionHoldingfunctionThe odds of a roll with some of its dice held: the held faces are settled, and only the rest are still to be thrown.
distributionOffunctionEvery total a spec can make and its chance.
encodeDiceWarfunctionA game of Dice War as text: its table, its seed and its moves, which is all there is to keep.
evaluateMathfunctionWhat a formula comes to, given each kind's total.
exactCountsfunctionThe odds as exact whole numbers, for the dice that have them: plain dice added up, one die kept from a pool (advantage), loaded and custom dice the same way (their weights are whole numbers, so their odds are exact fractions), and several such kinds added together while that stays quick.
ExactCountstypeThe odds as whole numbers: how many of the equally likely outcomes make each total.
expectedHighestfunctionThe average of the highest total among several throws of a roll.
expectedTotalfunctionThe average total over many rolls.
ExplodeKindtypeHow exploding dice are added up: each as a die of its own, all into the die that threw them (!!), or with one taken off each extra die (!p), or both (!!p).
EXPORT_FORMATconstantThe shape of the JSON this package writes.
ExportedtypeA whole JSON export.
exportedRollfunctionOne roll as the JSON export writes it.
ExportedRolltypeOne roll as the JSON export writes it.
FaceChancetypeOne face of a die and how often it comes up, beside how often it would on a fair one.
faceChancesfunctionEvery face of one die of a group with its chance, beside the fair die's.
faceRangefunctionThe lowest and highest face of one die.
faceStatsfunctionHow often each face of one kind of die came up in a history, with a chi-square test of whether that looks fair.
FaceStatstypeHow often each face of one kind of die came up, and whether that looks fair.
FairnesstypeWhat a fairness test makes of a die.
FAIRNESS_MINIMUM_EACHconstantThe fewest throws of each face a fairness test wants before it will say anything: the usual rule for a chi-square.
fairnessTestfunctionIs this die fair?
findPresetsfunctionThe presets a search finds: every word typed has to be in the name, another name, the one-line description or the notation.
formatNotationfunctionNotation for a spec: the inverse of parseNotation.
formulaTextfunctionA formula's roll with each kind of dice written as it fell: ([6 1]+3)*2-[3].
fromJSONfunctionRolls from JSON that toJSON wrote, or a history that serializeHistory did.
GameFamilytypeThe shelves the games are kept on.
getPresetfunctionA preset by its id, its name or any of its other names: getPreset("yahtzee") and getPreset("Yacht") are the same game.
groupOffunctionThe kind of dice one die of a roll belongs to, with its rules, faces and weights.
groupRangefunctionThe least and the most one kind of dice can total, its own rules applied.
groupsOffunctionThe kinds of dice in a roll, in order: the spec's own first, then the rest.
groupTotalsfunctionWhat each kind of dice of a roll came to, in order: what a formula puts together.
hasTotalfunctionWhether a roll's total says anything.
HISTORY_LIMITconstantA history keeps the latest rolls and forgets the oldest past this many.
isClothfunctionWhether a text names a cloth.
isDieSidesfunctionOne of the dice the tray has a button for.
isFairfunctionWhether a roll is of plain fair dice and nothing else: no loaded die, and no custom die either, whose faces are whatever somebody made them.
isLoadedfunctionWhether a roll has a loaded die in it.
isPlainDicefunctionWhether a kind of dice is plain enough to be rolled in any number: a fair numbered or Fate die, all added or one kept, under no other rule.
isSidesfunctionAny die this package can throw: two to a thousand sides, or a Fate die.
isSuccessRollfunctionWhether the first thing a roll says is a number of successes: every kind of dice in it is counted.
KeeptypeWhich dice count towards the total.
keptCountfunctionHow many dice of one group count towards the total.
keptFacesfunctionWhich faces count towards the total when one is kept.
KOROKORO_CLOTHSconstantTHE CLOTHS A TRAY MAY BE LAID IN: the same five the whole family offers, and itsutsu.com's boards — green (the tray's own, unless said), blue, red, black, and wood.
LOADED_PRESETSconstantThree loaded dice to try, each an old trick with a long record.
LoadedPresettypeLoaded dice, kept in one place and in plain sight.
loadedWeightsfunctionA loaded die's weights, checked and in lowest terms: one whole number from 0 to MAX_WEIGHT for each face, at least two faces that can come up.
loadHistoryfunctionRead a kept history.
loadingOffunctionWhat a loaded die's loading comes to, as exact fractions, for the face it favours most: { face: 6, loaded: [3, 8], fair: [1, 6] } is "6 comes up 3 in 8, not 1 in 6".
loadSetsfunctionThe sets kept on a device.
luckOffunctionHow lucky a total was, from 0 (the worst the dice can do) to 1 (the best): the share of rolls it beats, counting a tie as half.
makeSetfunctionA set from a name and a roll, or null when the name is empty or too long or the dice cannot be rolled.
MathFunctiontypeThe functions a formula may call.
mathGroupsfunctionWhich kinds of dice a formula uses, in the order it names them.
MathNodetypeArithmetic over the kinds of dice in a roll: (2d6+3)*2, 1d20-1d4, floor(4d6/2), max(1d6,1d8).
MathProblemtypeWhy a formula cannot be used, when it cannot.
mathRangefunctionThe least and the most a sound formula can come to, given each kind's range.
mathTextfunctionA formula as notation writes it, with brackets only where they are needed.
MAX_DICEconstantThe most dice in one roll: a fireball's 8d6, Farkle's six and a pool of ten all fit.
MAX_DICE_BY_CODEconstantThe most dice in one roll made from code, for a caller that asks: parseNotation(text, { maxDice }), normalizeSpec(spec, { maxDice }) and roll(spec, source, { maxDice }) each take a roll past MAX_DICE up to this.
MAX_EXPLODING_SIDESconstantThe largest die that may explode: past this the exact odds stop being quick to count.
MAX_EXPLOSIONSconstantHow many more dice one exploding die may throw.
MAX_FACE_VALUEconstantThe largest number a custom face may be worth, either way.
MAX_FACESconstantThe most faces a custom die has, and the fewest is two.
MAX_GROUPSconstantThe most kinds of dice in one roll: 1d20+1d4 is two.
MAX_LABELconstantThe longest a custom face's words may be, in characters.
MAX_LOADED_SIDESconstantThe largest die that may be loaded.
MAX_MATH_AMOUNTconstantThe largest amount, either way, any step of a formula may come to.
MAX_MATH_DIVISORconstantThe largest bottom of a fraction any step may have: what it may be divided by, all told.
MAX_MATH_NODESconstantThe most steps a formula may have.
MAX_MATH_NUMBERconstantThe largest whole number written in a formula.
MAX_MATH_PAIRSconstantThe most pairs of amounts any one step of a formula's odds may have to put together.
MAX_MATH_TOTALSconstantThe widest span of totals a formula may have.
MAX_MODIFIERconstantThe largest bonus, either way: a roll adds or takes away at most this.
MAX_REROLLSconstantHow many times one die is thrown again by a reroll-until (r<).
MAX_ROLL_LABELconstantThe longest a roll's label may be, in characters.
MAX_SET_NAMEconstantThe longest a set's name may be, in characters.
MAX_SETSconstantThe most sets kept on one device.
MAX_SIDESconstantThe most sides a numbered die has.
MAX_TIMESconstantThe most times one roll may be repeated as a set: 6#4d6dl1 is six.
MAX_UNIQUE_SIDESconstantThe largest die whose dice may be asked to all differ (u).
MAX_WEIGHTconstantThe heaviest a face of a loaded die may be weighted.
mayExplodefunctionWhether the dice may explode: numbered dice of a hundred sides or fewer, all of them kept.
mayRerollfunctionWhether a reroll at this face leaves something to do: it must reroll the lowest face and spare the highest.
mayRerollUntilfunctionWhether a die may be rerolled until it clears this face: the reroll must match the lowest face and no more than half of them.
meetsfunctionWhether a number meets a comparison.
MIN_DICEconstantThe fewest dice in one roll.
MIN_SIDESconstantThe fewest sides a numbered die has: a coin.
mostLikelyfunctionThe most likely totals: several when the peak is flat, as it is for one die.
mountDiefunctionPut one die in an element.
mountRollerfunctionPut a dice tray into an element.
newSeedfunctionA short seed anybody can read aloud or type: eight letters and digits.
normalizeSpecfunctionA spec brought into range, so a hand-typed or stored one can never roll eleven dice, five kinds or a die with no faces.
NotationChecktypeWhat checkNotation found: the spec, or the part it refused and why.
NotationOptionstypeHow to read a notation.
NotationProblemtypeDice notation, the way a character sheet writes it.
OutcometypeHow a roll is read in a game.
OutcomeOddstypeOne line of a game's odds: an outcome, the words for it, and its chance as a whole-number count of the equally likely throws.
parseHistoryfunctionA kept history read back from its text.
parseNotationfunctionA spec from notation, or null when the text is not dice this roller can throw.
parseSetsfunctionSets read back from their text.
patternsOffunctionEvery way the dice of a spec can fall, kind by kind, each with how many of the equally likely throws fall that way.
playDiceWarfunctionThe game after this move, or null for one the rules refuse: the game is over, a person's dice are missing or are not dice of this game, or dice are handed in for a seat that does not roll them.
playsByNewRulesfunctionWhether a kind of dice is played by a rule added in 1.7.0, one that changes what it can total: a reroll or an explosion at a comparison, compounding or penetrating dice, min or max, or counted successes.
PlaySoundtypeAnything that makes a roll's sound: the built-in one, or a page's own.
PresettypeThe dice for a game, and how the game reads them.
presetOddsfunctionThe exact odds of each outcome of a game's first roll: a natural in craps, each hand in chinchirorin, each result of a Risk battle.
PresetReadingtypeWhat a game makes of a roll: the outcome, and the words for it.
PresetRolltypeA game's dice thrown and read.
presetsconstantGame presets with their dice, readings and English/Japanese help.
PRESETSconstantGame presets with their dice, readings and English/Japanese help.
presetSpecfunctionA preset's dice, as a spec.
randomIntfunctionA fair integer in [0, n).
RandomSourcetypeWhere the randomness comes from.
rangeOffunctionThe lowest and highest totals a spec can produce.
readDicefunctionWhat happened to each die of a roll, from its faces alone: which were rerolled, which exploded, which were dropped.
readDiceAsfunctionRead a roll the way a reading does, with the rolls before it in the same game where that matters.
READING_WORDSconstantEnglish and Japanese outcome text, keyed by reading.outcome.
ReadingIdtypeThe name of a reading.
readPresetfunctionRead a roll the way a game does.
readResultsfunctionResults typed or pasted from a real die, such as 3 5 6 6 1 or 3,5,6: whole numbers separated by spaces, commas or new lines.
readSetfunctionA set from a link's query, or null when it holds none or its dice cannot be rolled.
readSharedfunctionA shared roll from a query string, or null when it does not describe one this roller could have thrown.
readSharedManyfunctionA shared set of rolls from a query string, or null when it does not hold one: as many rolls as the notation's # says, each with faces its dice could show.
resultTextfunctionA roll's result as it would be said: its total, or for dice that are only words, the words.
rollfunctionThrow the dice.
RolltypeOne throw of the dice: what was asked for, every die thrown, and the total.
RollerHandletypeWhat mountRoller hands back: the tray, driven from code.
RollerOptionstypeEverything a tray can be told when it is mounted.
RollerSizetypeHow much of the tray is drawn: the felt alone, the felt and the choice of dice, or all of it.
RollerStringstypeEvery word the tray says, in English and Japanese.
rollFromfunctionA roll put back together from its spec and its faces: for a history read from storage and a roll read from a link.
rollHeldfunctionHold some dice of a roll and throw the rest again, as Yacht and Farkle do.
rollLabelfunctionA roll's label, checked: a few words with no control characters and nothing notation is written with, or undefined.
rollManyfunctionThrow the same dice several times in one go, as ability scores are rolled: 4d6dl1 six times.
RollOptionstypeWhat roll and rollMany may be told beside the dice and the source.
rollPresetfunctionThrow a game's dice and read them.
RollSettypeThe same roll thrown several times in one go, with what the set comes to.
RollSoundtypeThe tray's own sound: play for each throw, close when the tray goes.
RollSpectypeWhat to roll: the dice, the bonus, and the rules.
rollTextfunctionOne roll on one line: 2d20kh1+5: 22 [17 (4)], or for a formula (2d6+3)*2: 20 ([6 1]+3)*2.
rulesTextfunctionThe modifiers of one kind of dice as notation writes them, in the one order they are written: >=8f=1!, r<3kh3.
runClifunctionRun the command line.
saveHistoryfunctionKeep a history.
seededSourcefunctionsfc32 started from a text seed: the same seed gives the same rolls on every platform, forever.
serializeHistoryfunctionA history as text, to keep in a browser's storage or anywhere else.
serializeSetsfunctionSets as text, to keep in storage.
setOffunctionWhat a set of rolls comes to: their sum, the highest and the lowest.
setQueryfunctionA set as a link's query: the dice and the name, for anybody to open and keep.
SHARE_VERSIONconstantThe version of the notation a link is written in.
shareQueryfunctionA roll as a link.
shareQueryManyfunctionA set of rolls as a link: the notation with its 6#, and every roll's faces, the rolls parted by semicolons.
SidestypeA die of any size from a coin to a d1000, or a Fate die, whose faces are −1, 0 and +1.
sidesOffunctionThe kind of die one die of a roll is.
soundMathfunctionA formula given by hand, checked for its shape alone: the nodes are what they say they are.
SoundThrowtypeThe sound of a roll: a shake while the dice tumble and a knock as each one lands.
specOffunctionA spec from its kinds of dice and a bonus, brought into range.
spreadMathfunctionThe odds of a formula: the chance of each whole number it can come to, given the chance of each total of each kind of dice.
spreadOffunctionHow far a typical roll lands from the average.
startDiceWarfunctionA new game, or null for a table it is not played at: fewer than two or more than eight players, dice or sides out of range, a goal out of range.
StatstypeEverything worth saying about a history of rolls.
statsOffunctionStats for a history, oldest roll first.
StorageLiketypeThe storage a browser offers, or anything shaped like it.
storeSetsfunctionKeep the sets.
STRINGSconstantThe built-in words, in English and Japanese.
toCSVfunctionRolls as CSV for a spreadsheet: a header, then a row for each roll, lines ended CRLF as RFC 4180 has them.
toJSONfunctionRolls as JSON, two spaces deep, with the format's number first.
totalOffunctionThe kept faces added up, plus the bonus.
totalStatsfunctionThe totals of every roll of one spec in a history, beside what the odds expect.
TotalStatstypeThe totals of one spec: seen against what the odds promise.
toTextfunctionRolls as plain text, one to a line, each with its time in UTC, oldest first as given.
TypedResultstypeWhat readResults found in somebody's typed results.
valueOfFacefunctionWhat a face of a group's die is worth in a total: its number, or for a custom face its value, which is 0 when it is only words.
VERSIONconstantThe version of this package, as package.json has it.
waysToShutfunctionEvery way to make a total from different numbers 1 to 9, largest first: the tiles a Shut the Box roll may shut.
withoutSetfunctionThe sets without the one of that name.
withSetfunctionThe sets with one added, newest first.
yahtzeeWithinfunctionThe chance of a Yahtzee (five dice alike) within a number of rolls, holding the largest group each time: 1 roll is 1 in 1296, and the usual three come to 347897 in 7558272, about 4.6%.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/korokoro 1.16.0.