Fast Random Integer Generation in an Interval

05/28/2018
by   Daniel Lemire, et al.
0

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 like 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., 32 bits, 64 bits) 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.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
03/08/2020

The Fast Loaded Dice Roller: A Near-Optimal Exact Sampler for Discrete Probability Distributions

This paper introduces a new algorithm for the fundamental problem of gen...
research
11/09/2021

An Empirical Study of Automated Unit Test Generation for Python

Various mature automated test generation tools exist for statically type...
research
04/19/2020

A practical approach to testing random number generators in computer algebra systems

This paper has a practical aim. For a long time, implementations of pseu...
research
05/18/2018

Towards Taming Java Wildcards and Extending Java with Interval Types

Of the complex features of generic nominally-typed OO type systems, wild...
research
05/08/2017

A revision of the subtract-with-borrow random number generators

The most popular and widely used subtract-with-borrow generator, also kn...
research
11/24/2019

Probabilistic methods of bypassing the maze using stones and a random number sensor

In this paper, some open questions that are posed in Ajans' dissertation...
research
10/25/2018

Random Sampling: Practice Makes Imperfect

The pseudo-random number generators (PRNGs), sampling algorithms, and al...

Please sign up or login with your details

Forgot password? Click here to reset