randomInt関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
A fair integer in [0, n). Rejection sampling, never next() % n: the modulo
leans towards the low faces whenever n does not divide 2^32, and a d6 or a
d10 does not.
インポート
import { randomInt } from "@johnmorrisdotca/korokoro";
定義
function randomInt(source: RandomSource, n: number): number
引数
| 名前 | 型 | 説明 |
|---|---|---|
source | RandomSource | A source of unsigned 32-bit integers; crypto by default where optional. |
n | number | The threshold, denominator or exclusive upper bound used by this call. |
戻り値
number
A fair integer in [0, n). Rejection sampling, never next() % n: the modulo leans towards the low faces whenever n does not divide 2^32, and a d6 or a d10 does not.
例
import { randomInt } from "@johnmorrisdotca/korokoro";
import { seededSource } from "@johnmorrisdotca/korokoro";
console.log(randomInt(seededSource("table"), 6));0出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。