rStats.js v1.3.0
    Preparing search index...

    Function RNGkind

    • Reads or changes the kinds of random number generation. Equivalent to R's RNGkind().

      • kind: "Mersenne-Twister" (or "default"): R's default generator.
      • kind: "L'Ecuyer-CMRG": L'Ecuyer's MRG32k3a, with independent streams for parallel work (nextRNGStream, nextRNGSubStream).
      • sampleKind: "Rounding": indices drawn as floor(n * u), as sample, sampleInt and rwilcox did in R before 3.6.0 (slightly non-uniform for large n; R warns about it, rStats.js does not). "Rejection" (or "default") is R's default since 3.6.0. Other functions are not affected.

      As in R, changing kind seeds the new generator from the next uniform of the current one (also when the kind does not change), so a stream stays reproducible from the last setSeed; changing only sampleKind keeps the stream. Call setSeed afterwards to seed the new generator directly: RNGkind({ kind }); setSeed(seed) is R's set.seed(seed, kind). Also as in R, a call that gives a kind seeds a generator that has not been seeded yet (from the clock, as a first draw would); a call without kinds only reads them.

      Parameters

      • options: RNGKindOptions = {}

        The kinds to change; omitted entries are kept. Default: change nothing.

      Returns RNGKinds

      The kinds in effect before the call (the current ones when called without options), as R.

      RangeError for an unsupported kind (nothing is changed then).

      RNGkind(); // { kind: "Mersenne-Twister", normalKind: "Inversion", sampleKind: "Rejection" }
      RNGkind({ kind: "L'Ecuyer-CMRG" });
      setSeed(1);
      runif(2); // [0.6775328286287442, 0.4273457228876442]
      // R: set.seed(1, kind = "L'Ecuyer-CMRG"); runif(2)
      RNGkind({ kind: "default", sampleKind: "Rounding" });
      setSeed(1);
      sampleInt(10, { size: 3 }); // [2, 3, 4]
      // R: set.seed(1, kind = "default", sample.kind = "Rounding"); sample.int(10, 3) - 1