0

Let us suppose that I have a full cycle LCG, following the standard equation

enter image description here

Hence, as it has a full cycle, it will have a period of m, and will output values ranging from 0 to m. However, I want to limit the output values to somewhere between 0 to some arbitrary constant a, where a is less than m. All the while maintaining its original period length.

I don't have experience in this field, but I was thinking that wherever I want to use the output value, I just take mod a of the number, and be done with it? will this ruin the randomness or is a valid solution?

How do I go about doing this?

  • If memory serves, the lowest order bits of a LCG are not generally the most random ones .. so this exact idea (mod) is probably not advised. But you've got the right basic idea .. postprocess the raw random bits coming out of the generator, into some kind of (eg) uniform distribution over the desired range. There should be lots of prior art here .. these things are (for instance) provided by the C++ standard library by now, maybe look at how they do it? – rchilton1980 Jan 06 '21 at 19:13
  • I didn't understand what did you mean by lowest order bits of an LCG? Do you mean the ending digits of the number? – Akshat Mehrotra Jan 06 '21 at 20:46
  • Yes, that's in effect what mod is doing. For instance, mod a=32 will pick off the lowest 5 bits (other choices of a are similar, even those are not exact powers of 2 will still overemphasize the lower bits over the higher ones). – rchilton1980 Jan 06 '21 at 21:03

0 Answers0