RNGs Using Integer Array Shuffling with the HP Prime

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
One Dimensional Arrays
Generating Random Numbers
CMSC 104, Version 9/011 Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class Project Incremental.
Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Random Number Generators Jake Blanchard Spring 2010 Uncertainty Analysis for Engineers1.
Analysis of Algorithms CS 477/677 Linear Sorting Instructor: George Bebis ( Chapter 8 )
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
Event-drive SimulationCS-2303, C-Term Project #3 – Event-driven Simulation CS-2303 System Programming Concepts (Slides include materials from The.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
11.3 Function Prototypes A Function Prototype contains the function’s return type, name and parameter list Writing the function prototype is “declaring”
ARRAYS AND POINTERS Although pointer types are not integer types, some integer arithmetic operators can be applied to pointers. The affect of this arithmetic.
COMPE575 Parallel & Cluster Computing 5.1 Pipelined Computations Chapter 5.
CSCE Monte Carlo Methods When you can’t do the math, simulate the process with random numbers Numerical integration to get areas/volumes Particle.
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
MergeSort Source: Gibbs & Tamassia. 2 MergeSort MergeSort is a divide and conquer method of sorting.
 Pearson Education, Inc. All rights reserved Arrays.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
ICS220 – Data Structures and Algorithms Lecture 10 Dr. Ken Cosh.
MATH 224 – Discrete Mathematics
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
Lists in Python.
1 Sorting in O(N) time CS302 Data Structures Section 10.4.
Sorting HKOI Training Team (Advanced)
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
VB Arrays Chapter 8 Dr. John P. Abraham Professor UTPA.
Probability Theory 1.Basic concepts 2.Probability 3.Permutations 4.Combinations.
1 Chapter 13 Recursion. 2 Chapter 13 Topics l Meaning of Recursion l Base Case and General Case in Recursive Function Definitions l Writing Recursive.
CS433 Modeling and Simulation Lecture 15 Random Number Generator Dr. Anis Koubâa 24 May 2009 Al-Imam Mohammad Ibn Saud Islamic University College Computer.
CPSC 531: RN Generation1 CPSC 531:Random-Number Generation Instructor: Anirban Mahanti Office: ICT Class Location:
Chapter 7 Random-Number Generation
Basic Concepts in Number Theory Background for Random Number Generation 1.For any pair of integers n and m, m  0, there exists a unique pair of integers.
Modeling and Simulation Random Number Generators
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Random Number Generators 1. Random number generation is a method of producing a sequence of numbers that lack any discernible pattern. Random Number Generators.
Comp 335 File Structures Hashing.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
APPENDIX D R ANDOM N UMBER G ENERATION Organization of chapter in ISSO* – General description and linear congruential generators Criteria for “good” random.
 2008 Pearson Education, Inc. All rights reserved Case Study: Random Number Generation C++ Standard Library function rand – Introduces the element.
Can’t provide fast insertion/removal and fast lookup at the same time Vectors, Linked Lists, Stack, Queues, Deques 4 Data Structures - CSCI 102 Copyright.
CompSci 100E 3.1 Random Walks “A drunk man wil l find his way home, but a drunk bird may get lost forever”  – Shizuo Kakutani Suppose you proceed randomly.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
Data Collections: Lists CSC 161: The Art of Programming Prof. Henry Kautz 11/2/2009.
Probabilistic Analysis and Randomized Algorithm. Average-Case Analysis  In practice, many algorithms perform better than their worse case  The average.
Programming Multi-Core Processors based Embedded Systems A Hands-On Experience on Cavium Octeon based Platforms Lab Exercises (Lab 2: Sorting)
1 Sorting. 2 Introduction Why is it important Where to use it.
Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2.Solve smaller instances.
Sorting Data Structures and Algorithms (60-254). Sorting Sorting is one of the most well-studied problems in Computer Science The ultimate reference on.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
CMSC 104, Version 8/061L10ArithmeticOps.ppt Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Review 1 Insertion Sort Insertion Sort Algorithm Time Complexity Best case Average case Worst case Examples.
R ANDOM N UMBER G ENERATORS Modeling and Simulation CS
Hash Tables Ellen Walker CPSC 201 Data Structures Hiram College.
CSE 251 Dr. Charles B. Owen Programming in C1 Intro to Arrays Storing List of Data.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
0 Simulation Modeling and Analysis: Input Analysis 7 Random Numbers Ref: Law & Kelton, Chapter 7.
CS 116 Object Oriented Programming II Lecture 13 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Advanced Sorting 7 2  9 4   2   4   7
Presented by Namir Shammas
3.1 Algorithms (and real programming examples).
Suppose I want to add all the even integers from 1 to 100 (inclusive)
Quick-Sort 2/25/2019 2:22 AM Quick-Sort     2
Quick-Sort 4/8/ :20 AM Quick-Sort     2 9  9
Linear Time Sorting.
Presentation transcript:

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

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: http://home.citycable.ch/pierrefleur/Jacques-Laporte/ Jacque’s simulators are found here: http://wiki.epfl.ch/polymac/simulators Maintained by Francois Roulet (visits the HP Museum web sites)

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

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.

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.

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.

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.

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.

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.

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.

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 1000 random numbers, with an offset of 0.1357, using 14 loops to shuffle the pages of integers, with a sequence of 1 to 1000 in increments of 1.

HP Prime Code

HP Prime Code

HP Prime Code

Thank You!!