区间上的快速随机序列生成
Fast Random Integer Generation in an Interval
摘要:
在模拟、概率算法和统计测试中,我们经常在一个区间内生成随机整数(例如,[0,s))。例如,区间中的随机整数对于Fisher-Yates随机洗牌是必不可少的。因此,像Java、Python、C++、Swift和Go这样的流行语言都将范围随机整数生成函数作为其运行时库的一部分。伪随机值通常以固定比特数的字生成(例如,32位、64位)使用诸如线性同余生成器之类的算法。我们需要函数将这些随机单词转换为区间([0,s))中的随机整数,而不会引入统计偏差。诸如Java之类的程序设计语言中的标准函数涉及整数除法。不幸的是,除法指令相对昂贵。我们回顾了一个无偏函数,从一个避免整数除法的随机单词源生成范围整数。要建立的方法的实用性,我们表明,该算法可以乘以x64处理器上的无偏随机洗牌的速度。我们提出的方法已经被Go语言用于其shuffle函数的实现。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。