Linear Congruential Generators, Bays-Durham Shuffle

In summary: NG output stream to first element (13 in this case) of S, then repeat following until output stream has n elements.get next number s from Sform the index j into the table (j = s mod k)get jth element of table and add it to the output streamreplace jth element of table with sHere's Mathcad-produced list of the a 5-number sequence:1, 2, 3, 4, 5.And the algorithm ...Here's the algorithm in Mathcad:form the table of length k from an Linear Congruential Generator (LCG). initialize RNG output stream to first element (
  • #1
koenigcochran
15
0
Hi!

I've got an idea of how LCGs work. However, I'm reading "Exploring Monte Carlo Methods" and came across the Bays-Durham Shuffle, a means of getting rid of low-order correlations in the minimal standard LCG.

The outline of this algorithm in the book makes no sense to me. Can someone summarize the algorithm?
 
Technology news on Phys.org
  • #2
koenigcochran said:
Hi!

I've got an idea of how LCGs work. However, I'm reading "Exploring Monte Carlo Methods" and came across the Bays-Durham Shuffle, a means of getting rid of low-order correlations in the minimal standard LCG.

The outline of this algorithm in the book makes no sense to me. Can someone summarize the algorithm?

I don't know if this is any improvement on what you read, but ...

Create the table of length k from an Linear Congruential Generator (LCG). Continue the LCG to create a stream S of length n. Initialize RNG output stream to first element (13 in this case) of S, then repeat following until output stream has n elements ..
  • get next number s from S
  • form the index j into the table (j = s mod k)
  • get jth element of table and add it to the output stream
  • replace jth element of table with s

Here's Mathcad-produced list of the a 5-number sequence:


And the algorithm ...

The worksheet is attached (unless it's too big!)
 

Attachments

  • phys - 12 05 31 Bays Durham Shuffle 02.jpg
    phys - 12 05 31 Bays Durham Shuffle 02.jpg
    26.2 KB · Views: 699
  • phys - 12 05 31 Bays Durham Shuffle 01.jpg
    phys - 12 05 31 Bays Durham Shuffle 01.jpg
    38.3 KB · Views: 615
  • phys = 12 05 31 Bays Durham 01.mcd
    39.2 KB · Views: 429
  • #3
Three things

(1) The illustration of the table and output stream were very helpful; thank you so much! I think its the diction that has confused me--I would describe the algorithm with a choice of words totally different from what I've found in literature (probably just a consequence of my background).
(2) Did you use an initial seed 8 and divisor 30 in the image of the table and output stream? I'd like to check my own implementation of the shuffle.
(3) For your name's sake, I hope you've seen "Little Nemo: Adventures in Slumberland." A trippy, childhood favorite.

Thanks again!
 
  • #4
Also:

Is the final vector of 'random' numbers the appendage of the output stream to the table? Just the table? Just the output stream? Or does it matter?

Thanks Nemo.
 
  • #5
Disregard that last question, I've answered it for myself. The output stream is of arbitrary length and should be used as the vector of 'random' numbers.

However the question remains: does the length of the table matter? Is there an optimal length?
 
  • #6
koenigcochran said:
Three things

(1) The illustration of the table and output stream were very helpful; thank you so much! I think its the diction that has confused me--I would describe the algorithm with a choice of words totally different from what I've found in literature (probably just a consequence of my background).
(2) Did you use an initial seed 8 and divisor 30 in the image of the table and output stream? I'd like to check my own implementation of the shuffle.

No, I used an initial seed of 9. The '8' is the length of the 'shuffle' table and '30' is the length of the output vector. What you wouldn't have seen without Mathcad is the first half of the worksheet containing the LCG. See attached, the LCG agrees with the sequence given in Gentle.

(3) For your name's sake, I hope you've seen "Little Nemo: Adventures in Slumberland." A trippy, childhood favorite.
Nope, but my children probably have. My name's more to do with the Latin I studied at school.

Thanks again!
No problem.
 

Attachments

  • phys - 12 06 01 Bays Durham Shuffle 01.jpg
    phys - 12 06 01 Bays Durham Shuffle 01.jpg
    36.3 KB · Views: 623
  • #7
koenigcochran said:
I'd like to check my own implementation of the shuffle.
I'm reasonably certain that my LCG implementation is correct (or I've made the same mistake as the original implementation!), however, I'm not so sure about the Bays-Durham algorithm. The initial 3 numbers agree with those given by Gentle, but the plot of successive pairs is completely different. I can see a pattern of sorts in Gentle's plot but mine appears to be far more random, even in the 3D version (it's really interesting to compare the 'before' and 'after' shuffle plots). So, there is a possibility that I'm either plotting the data incorrectly and/or I've made an error in the implementation that doesn't show up until later in the sequence. I've had a brief webtrawl but can't find anything better to check against at the moment.

NR
 

Related to Linear Congruential Generators, Bays-Durham Shuffle

1. What is a Linear Congruential Generator (LCG)?

A Linear Congruential Generator is a type of pseudorandom number generator that uses a linear equation to generate a sequence of numbers that appear to be random. The equation typically takes the form of Xn+1 = (aXn + c) mod m, where Xn is the previous number in the sequence, a and c are constants, and m is the modulus.

2. How does an LCG work?

An LCG works by starting with a seed value, which is the first number in the sequence. This seed value is then plugged into the linear equation to generate the next number in the sequence. This process is repeated to generate as many numbers as needed. The resulting sequence may appear random, but it is actually determined by the initial seed value and the constants used in the equation.

3. What is the Bays-Durham Shuffle?

The Bays-Durham Shuffle is a method for improving the randomness of an LCG. It involves shuffling the output of the LCG using a different algorithm, such as a bitwise XOR operation, before using it as the next seed value. This helps to reduce patterns in the generated sequence and improve the overall randomness.

4. What are the advantages of using LCGs and the Bays-Durham Shuffle?

LCGs are relatively easy to implement and computationally efficient, making them useful for generating large numbers of random values. The Bays-Durham Shuffle can improve the randomness of an LCG, making it more suitable for applications where a high level of randomness is desired, such as in cryptography.

5. Are there any drawbacks to using LCGs and the Bays-Durham Shuffle?

One drawback of using LCGs is that the generated sequence is deterministic, meaning that it will produce the same sequence every time if given the same seed value and constants. This makes LCGs unsuitable for certain applications, such as simulations that require true randomness. Additionally, the Bays-Durham Shuffle may not completely eliminate patterns in the generated sequence, and the resulting numbers may still not be truly random.

Similar threads

  • Programming and Computer Science
Replies
1
Views
665
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
1K
  • STEM Academic Advising
Replies
13
Views
2K
Replies
1
Views
2K
Replies
75
Views
8K
Replies
4
Views
1K
Replies
1
Views
1K
  • General Engineering
Replies
16
Views
6K
Back
Top