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

    Function sampleInt

    • Random sample of integers from 0..n-1. Equivalent to R's sample.int(). Unlike R, it is 0-based.

      The result is R's sample.int(n, ...) minus 1, so it can be used directly as array indices. It consumes the same random numbers as R (default sample.kind = "Rejection").

      Parameters

      • n: number

        Number of candidates: a non-negative number up to 4.5e15 (2^52, as R); below 2^31 with prob, and for sampling without replacement more than n / 2 of them.

      • options: SampleOptions = {}

      Returns number[]

      The drawn integers, each in 0..n-1.

      setSeed(42);
      sampleInt(10, { size: 3 }); // [0, 4, 9] (R: set.seed(42); sample.int(10, 3) - 1)