The base::sample function uses a slightly biased algorithm for creating random integers within a given range. As an alternative the algorithm suggested by Daniel Lemire (2018, <arXiv:1805.1094>) is used. The package is motivated by a thread on R-devel.

Installation

At the moment dqsample is not on CRAN, but you can install the current version via drat:

Example

When sampling many random integers the density of odd and even numbers should be roughly equal and constant. This is not the case with base::sample:

While it is the case with dqsample::sample:

This particular sample for the bias was found by Duncan Murdoch.