リファレンス
乱数列・抽選・シード
import { … } from "@johnmorrisdotca/tane";
最小化と gzip 圧縮をしたサイズは 9.8 kB(読み込むものをすべて含み、esbuild で計測)
リファレンスの説明と例は英語です。見出しと目次は日本語です。
Tane 種: seeded random numbers and daily seeds.
One seed, the same numbers everywhere: a small generator, the draws a game
needs from it, seeds that travel in an address with ranges kept aside, one
seed a day, and a stream's position written down and read back. No
dependencies and no DOM; @johnmorrisdotca/tane/react adds two hooks, and
tane is the same thing from a terminal.
エクスポート
| 名前 | 種類 | 概要 |
|---|---|---|
addDays | 関数 | The day by days after (or, negative, before) a day. |
below | 関数 | An integer in [0, n): one draw. |
chance | 関数 | True with probability p, from 0 (never) to 1 (always): one draw. |
checkBlocks | 関数 | The blocks in ascending order, checked: whole numbers, inside 1 to most, none overlapping another. |
CLI_MAX_COUNT | 定数 | The most numbers one run prints. |
cliLanguage | 関数 | The language the command line speaks: --lang, or the environment's, or the system's; Japanese for ja…, English for anything else. |
CliResult | 型 | What the command line came to. |
CliSurroundings | 型 | What the command line is run in. |
counted | 関数 | A seeded stream that counts its own draws, so that it can be written down at any moment and picked up later: const random = counted(42), draw from it as from any stream, then keep random.position(). |
CountedRandom | 型 | A stream that knows where it is: call it for the next number, as any Random; read seed and draws, or take its position(). |
CSV_COLUMNS | 定数 | The columns of the CSV, in order. |
dailySeed | 関数 | Today's seed, the date as a number: 2026-09-30 is 20260930. |
dayKey | 関数 | The day a moment falls on, in UTC or in the named IANA time zone. |
DayKey | 型 | A calendar date, YYYY-MM-DD. |
dayOfSeed | 関数 | The day a seed names inside a block, or null for a seed that names none. |
daysBetween | 関数 | How many days to is after from: negative when it is before. |
daySeed | 関数 | A day's seed inside a block kept for it: the block's first seed plus the date as a number. |
deriveSeed | 関数 | A seed of its own for one part of something seeded: deriveSeed(game, "deck") and deriveSeed(game, "dice") are two unrelated streams from one game's seed, and adding a third part later moves neither. |
distinctBelow | 関数 | count different integers below limit, in the order drawn, by drawing again whenever a number comes up twice. |
drawSeed | 関数 | A seed from 1 to most, any of them as likely as another, skipping every reserved block: one draw. |
DrawSeedOptions | 型 | Where a drawn seed may land. |
fillIn | 関数 | Put values into a string's braces: fillIn("Seed {seed}", { seed: 42 }) is "Seed 42". |
float | 関数 | A number in [min, max): one draw. |
fork | 関数 | A new, independent stream split off another: it takes one draw from random and seeds a fresh generator from it. |
freshSeed | 関数 | A new seed for something nobody asked for by number, drawn from Math.random. |
fromJSON | 関数 | A position from JSON that toJSON wrote. |
fromText | 関数 | A position from a line toText wrote, with any space around it. |
hashSeed | 関数 | A seed from any text: hashSeed("room-7") is the same unsigned 32-bit integer everywhere. |
inBlock | 関数 | Whether a seed falls inside a block. |
int | 関数 | An integer from min to max, both included: one draw. |
isDayKey | 関数 | Whether a text is a real date written YYYY-MM-DD: 2026-02-30 is not. |
isSeed | 関数 | Whether a value read from outside (an address, a request body) is a seed: an integer from 1 to most. |
Language | 型 | The languages Tane speaks. |
languageOf | 関数 | The language a tag such as ja-JP or en_US.UTF-8 names: Japanese for anything that starts ja, English otherwise. |
MAX_CSV_ROWS | 定数 | The most rows toCSV writes at once. |
mulberry32 | 関数 | A seeded stream: mulberry32(42) returns the same numbers every time it is made. |
nextDayStart | 関数 | The first moment of the day after the one at falls on, in that zone: when a daily seed next changes. |
normal | 関数 | A number from a normal distribution (Box–Muller): two draws. |
pick | 関数 | One item of a list, each as likely as the next: one draw. |
Random | 型 | A number in [0, 1), like Math.random, from a stream a seed fixes. |
randomAt | 関数 | A stream that starts draws numbers into seed's: randomAt(42, 7)() is the eighth number of mulberry32(42), reached without drawing the first seven. |
runCli | 関数 | Run the command line. |
sample | 関数 | count items of a list, no item twice, in the order drawn: a partial Fisher–Yates, one draw each. |
SAVE_FORMAT | 定数 | The shape of the JSON and the text this package writes. |
savedStream | 関数 | A position as the object toJSON writes: the format, the seed, the draws and the state they come to. |
SavedStream | 型 | A stream's position as toJSON writes it. |
SEED_MOST | 定数 | The largest seed: it travels as a plain integer, so it stays a positive 32-bit signed one. |
SeedBlock | 型 | A range of seeds kept aside: from up to, not including, from + size. |
seededRandom | 関数 | A seeded stream. |
seedFrom | 関数 | A seed from whatever a person typed or a link carried. |
shuffle | 関数 | The list in place, in a random order (Fisher–Yates, from the end): one draw for each item but the first. |
shuffled | 関数 | A shuffled copy; the list given is left alone. |
stateAt | 関数 | The generator's state after draws numbers have been taken from seed: an unsigned 32-bit integer. |
step | 関数 | One step of mulberry32 as a pure function: the number drawn and the state to keep for the next one. |
Step | 型 | One draw and the state after it, for code that keeps the state itself (in a database row, say). |
StreamPosition | 型 | Where a stream is: the seed it started from, and how many numbers have been drawn from it. |
STRINGS | 定数 | Every string, in both languages. |
TaneStrings | 型 | The names of the strings. |
toCSV | 関数 | The next count numbers from a position as CSV for a spreadsheet: a header, then one row a draw, with the draw's number counted from 1, its value, and the generator's state after it. |
toJSON | 関数 | A position as JSON, two spaces deep, with the format's number first. |
toText | 関数 | A position as one line to paste into a chat or a bug report: tane:1:42:7 is format 1, seed 42, 7 draws in. |
VERSION | 定数 | The version of this package, as package.json has it. |
weightedIndex | 関数 | An index into weights, each chosen in proportion to its weight: one draw. |
weightedPick | 関数 | One item, chosen by the matching weight: one draw. |
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。