Presentation is loading. Please wait.

Presentation is loading. Please wait.

RNGs Using Integer Array Shuffling with the HP Prime

Similar presentations


Presentation on theme: "RNGs Using Integer Array Shuffling with the HP Prime"— Presentation transcript:

1 RNGs Using Integer Array Shuffling with the HP Prime
Presented by Namir Shammas

2 Dedication Remembering Jacque Laport and his fantastic web site for basic calculation algorithms (including CORDIC) used in HP-35 calculators. Jacques passed away on January 5, 2015, in his home in Paris. He was 68. His web site can be now found at: Jacque’s simulators are found here: Maintained by Francois Roulet (visits the HP Museum web sites)

3 There is Strength in Numbers!
This really sums it up!

4 Basic Concepts Inspired by the randperm() function in Matlab. It returns an array of random non-repeating integers. Take a sequence of integers (and even numbers with fractions) and repeatedly shuffled it. Reverse of sorting an array of integers. Using integers makes the results very reproducible on different programming languages, operating systems, and hardware.

5 Basic Concepts (cont.) No modulus function used.
No heavy reliance on floating point arithmetic. Start with a sequence of integer and shuffle/scramble it as much as possible. The three rules of shuffling—scramble, scamble, scramble! The autocorrelation of the generated random numbers decreases with better shuffling.

6 Algorithm Initialize a sequence of integers and store it in an array.
Divide the array into N, say 10, buckets or pages. Repeatedly merge any two pages of integers, shuffle them, and split them back to their source pages. Use primes as offsets for swapping the elements in the page. Generate a (large) array of uniformly distributed random numbers.

7 Algorithm (cont.) The bigger the array, the better the quality of random numbers. Bigger arrays give you random numbers with finer resolution. Bigger arrays yield random numbers with lower autocorrelations.

8 Algorithm (cont.) The RNGs are computed using :
𝒙 𝒊 = 𝑰𝒏𝒕𝒆𝒈𝒆𝒓(𝒊) (𝑴𝒂𝒙_𝑰𝒏𝒕𝒆𝒈𝒆𝒓_𝑽𝒂𝒍𝒖𝒆+𝟏) Can return all the random numbers as an array or store the integers in a buffer and access them sequentially as needed.

9 Algorithm (cont.) Random numbers (per batch) are perfectly distributed in histograms in the range of 0 to 1. They have low autocorrelation values for a wide range of lags.

10 More Random Numbers? First option: Generate another set using a different offset value, array size and shuffling frequency. Second option: perform more shuffling on the same array of integers. Adding more “batches” of random numbers increases the autocorrelation of the random numbers in the entire set. Avoid multiple batches if you seek high quality random numbers.

11 HP Prime Code HP Prime applications are not expected to consume a huge number of random numbers. Use function MyRand(). Parameters are newOffset, newArraySize, newShuffleFreq, newValueInc, and bSetupVars. Here is a sample output for executing M1:=MyRand(0.1357,1000,14,1,1). It generates random numbers, with an offset of , using 14 loops to shuffle the pages of integers, with a sequence of 1 to 1000 in increments of 1.

12 HP Prime Code

13 HP Prime Code

14 HP Prime Code

15 Thank You!!


Download ppt "RNGs Using Integer Array Shuffling with the HP Prime"

Similar presentations


Ads by Google