User Tools

Site Tools


high_20quality_20random_20number_20generation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

high_20quality_20random_20number_20generation [2018/03/31 13:19]
127.0.0.1 external edit
high_20quality_20random_20number_20generation [2018/04/16 17:20] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====High Quality Random Number Generation===== =====High Quality Random Number Generation=====
  
-//by Richard Russell, March 2010//\\ \\  Listed below are BBC BASIC implementations of two high performance Pseudo Random Number Generators: the **WELL512A** and **WELL1024A** algorithms developed in 2006 (see this [[http://​en.wikipedia.org/​wiki/​Well_Equidistributed_Long-period_Linear|Wikipedia article]]). They have state sizes of 512 bits and 1024 bits, and therefore sequence lengths of 2^512-1 and 2^1024-1, respectively. They both return 32-bit signed integer values, but these can easily be converted to other formats, for example using the code snippets listed at [[/​Notes%20on%20the%20use%20of%20RND|Notes on the use of RND]].\\ \\  These **Well Equidistributed Long-period Linear** algorithms have long sequences, excellent statistical properties and are computationally simpler than some alternative methods. They are ideally suited to applications such as Monte Carlo simulations.\\ \\  In the listings below, BBC BASIC'​s RND function is used to provide the initialisation (seed). This might be adequate for some uses, but for more critical applications a seed with more entropy would be desirable. The '​state'​ information is contained in the array **State%()** and the variable **State_i%** which are passed by reference to the generator function. To '​replay'​ a sequence it is only necessary to save and restore these values.\\ +//by Richard Russell, March 2010//\\ \\  Listed below are BBC BASIC implementations of two high performance Pseudo Random Number Generators: the **WELL512A** and **WELL1024A** algorithms developed in 2006 (see this [[http://​en.wikipedia.org/​wiki/​Well_Equidistributed_Long-period_Linear|Wikipedia article]]). They have state sizes of 512 bits and 1024 bits, and therefore sequence lengths of 2^512-1 and 2^1024-1, respectively. They both return 32-bit signed integer values, but these can easily be converted to other formats, for example using the code snippets listed at [[/​Notes%20on%20the%20use%20of%20RND|Notes on the use of RND]].\\ \\  These **Well Equidistributed Long-period Linear** algorithms have long sequences, excellent statistical properties and are computationally simpler than some alternative methods. They are ideally suited to applications such as Monte Carlo simulations.\\ \\  In the listings below, BBC BASIC'​s RND function is used to provide the initialisation (seed). This might be adequate for some uses, but for more critical applications a seed with more entropy would be desirable. The '​state'​ information is contained in the array **State%()** and the variable **State_i%** which are passed by reference to the generator function. To '​replay'​ a sequence it is only necessary to save and restore these values. 
 + 
 +<code bb4w>
         REM BBC BASIC version of the WELL512A Pseudo Random Number Generator         REM BBC BASIC version of the WELL512A Pseudo Random Number Generator
         REM By Richard Russell, http://​www.rtrussell.co.uk/,​ v1.00, 30-Mar-2010         REM By Richard Russell, http://​www.rtrussell.co.uk/,​ v1.00, 30-Mar-2010
Line 30: Line 32:
         S%(I%) = S%(I%) EOR S%(I%)<<​2 EOR X% EOR X%<<​18 EOR Y%<<​28 EOR Z%         S%(I%) = S%(I%) EOR S%(I%)<<​2 EOR X% EOR X%<<​18 EOR Y%<<​28 EOR Z%
         = S%(I%)         = S%(I%)
-\\ +</​code>​ 
 + 
 +<code bb4w>
         REM BBC BASIC version of the WELL1024A Pseudo Random Number Generator         REM BBC BASIC version of the WELL1024A Pseudo Random Number Generator
         REM By Richard Russell, http://​www.rtrussell.co.uk/,​ v1.00, 30-Mar-2010         REM By Richard Russell, http://​www.rtrussell.co.uk/,​ v1.00, 30-Mar-2010
Line 58: Line 62:
         S%(I%) = S%(I%) EOR S%(I%)<<​11 EOR X% EOR X%<<7 EOR Y% EOR Y%<<​13         S%(I%) = S%(I%) EOR S%(I%)<<​11 EOR X% EOR X%<<7 EOR Y% EOR Y%<<​13
         = S%(I%)         = S%(I%)
 +</​code>​
 +
high_20quality_20random_20number_20generation.txt · Last modified: 2018/04/16 17:20 by richardrussell