Fast Random Integer Generation in an Interval

In simulations, probabilistic algorithms, and statistical tests, we often generate random integers in an interval (e.g., [0,s)). For example, random integers in an interval are essential to the Fisher-Yates random shuffle. Consequently, popular languages such as Java, Python, C++, Swift and Go include ranged random integer generation functions as part of their runtime libraries. Pseudo-random values are usually generated in words of a fixed number of bits (e.g., 32b, 64b) using algorithms such as a linear congruential generator. We need functions to convert such random words to random integers in an interval ([0,s)) without introducing statistical biases. The standard functions in programming languages such as Java involve integer divisions. Unfortunately, division instructions are relatively expensive. We review an unbiased function to generate ranged integers from a source of random words that avoids integer divisions with high probability. To establish the practical usefulness of the approach, we show that this algorithm can multiply the speed of unbiased random shuffling on x64 processors. Our proposed approach has been adopted by the Go language for its implementation of the shuffle function.

[1]  Pierre L'Ecuyer,et al.  Tables of linear congruential generators of different sizes and good lattice structure , 1999, Math. Comput..

[2]  Pierre L’Ecuyer,et al.  Random Number Generation , 2008, Encyclopedia of Algorithms.

[3]  Pierre L'Ecuyer,et al.  History of uniform random number generation , 2017, 2017 Winter Simulation Conference (WSC).

[4]  Takuji Nishimura,et al.  Mersenne twister: a 623-dimensionally equidistributed uniform pseudo-random number generator , 1998, TOMC.

[5]  Jens Gustedt Engineering Parallel In-Place Random Generation of Integer Permutations , 2008, WEA.

[6]  Pierre L'Ecuyer,et al.  On the xorshift random number generators , 2005, TOMC.

[7]  Michael Goesele,et al.  Is Your Permutation Algorithm Unbiased for n ≠ 2 m ? , 2011, PPAM.

[8]  Makoto Matsumoto,et al.  SIMD-Oriented Fast Mersenne Twister: a 128-bit Pseudorandom Number Generator , 2008 .

[9]  Paul Bratley,et al.  A guide to simulation , 1983 .

[10]  Peter W. Glynn,et al.  Stochastic Simulation: Algorithms and Analysis , 2007 .

[11]  Hans R. Künsch,et al.  A variant of importance splitting for rare event estimation: Fixed number of successes , 2011, TOMC.

[12]  Pavel Tvrdík,et al.  Algorithm 947 , 2014, ACM Trans. Math. Softw..

[13]  William B. Langdon,et al.  A fast high quality pseudo random number generator for nVidia CUDA , 2009, GECCO '09.

[14]  Kouros Owzar,et al.  permGPU: Using graphics processing units in RNA microarray association studies , 2010, BMC Bioinformatics.

[15]  Pierre L'Ecuyer,et al.  A search for good multiple recursive random number generators , 1993, TOMC.

[16]  Marvin K. Nakayama,et al.  Using permutations in regenerative simulations to reduce variance , 1998, TOMC.

[17]  Peter Sanders,et al.  Random Permutations on Distributed, External and Hierarchical Memory , 1998, Inf. Process. Lett..

[18]  Pierre L'Ecuyer,et al.  TestU01: A C library for empirical testing of random number generators , 2006, TOMS.

[19]  Luc Devroye,et al.  Random variate generation for multivariate unimodal densities , 1997, TOMC.

[20]  Mark A. Overton Romu: Fast Nonlinear Pseudo-Random Number Generators Providing High Quality , 2020, ArXiv.

[21]  Pierre L'Ecuyer,et al.  Random numbers for simulation , 1990, CACM.

[22]  Jeffrey Scott Vitter,et al.  Random sampling with a reservoir , 1985, TOMS.

[23]  W. Matthew Carlyle,et al.  Constructing nearly orthogonal latin hypercubes for any nonsaturated run-variable combination , 2012, TOMC.

[24]  Axel Bacher,et al.  Generating Random Permutations by Coin Tossing , 2017, ACM Trans. Algorithms.

[25]  Averill Law,et al.  Simulation Modeling and Analysis (McGraw-Hill Series in Industrial Engineering and Management) , 2006 .

[26]  A. Matteis,et al.  Parallelization of random number generators and long-range correlations , 1988 .

[27]  Takayuki Osogami,et al.  Finding probably best systems quickly via simulations , 2006, TOMC.

[28]  Vikas Singh,et al.  Speeding up Permutation Testing in Neuroimaging , 2013, NIPS.

[29]  Ronald L. Wasserstein,et al.  Monte Carlo: Concepts, Algorithms, and Applications , 1997 .

[30]  Michael C. Fu,et al.  History of seeking better solutions, AKA simulation optimization , 2017, 2017 Winter Simulation Conference (WSC).

[31]  Pierre L'Ecuyer,et al.  Random number generation with multiple streams for sequential and parallel computing , 2015, 2015 Winter Simulation Conference (WSC).

[32]  Art B. Owen,et al.  Latin supercube sampling for very high-dimensional simulations , 1998, TOMC.

[33]  Paul Bratley,et al.  A guide to simulation (2nd ed.) , 1986 .