0

I'm trying to solve the questions below in Matlab using a linear congruential generator. My line of code for the function is shown below. m is basically the maximum value of the range of values you can expect and so depends on the question. The initial seed x is determined first by the clock and then each random number is fed back into the function to produce a new one. The rules for picking lcg values are given here http://en.wikipedia.org/wiki/Linear_congruential_generator. What I need is good values for a and c for the designated period.

My lcg code

random_number = mod((a*x + c),m);
  • Q1 requires a random number between 1 and 52 (probability of poker hands)
  • Q2 requires a random number between 1 and 366 (birthday paradox)
  • Q3 requires a random number between 1 and 3 (Monty Hall Problem)
  • Q4 requires numbers between 1 and 1000

I know it may seem pretty simple but implementing this with small ranges tends to produce a pattern with a small period i.e. 4 digits repeating continually.

Also it may be possible to use a different m value and filter out any values outside my required range but honestly I don't think that should be necessary. Thanks very much

Serg
  • 2,346
  • 3
  • 29
  • 38
  • LCG's seem to prone to periodicity, especially with a small value of m. You could use a larger value of m and scale the output appropriately. (ref: http://stackoverflow.com/questions/6415424/ - see second answer + comments) – nkjt Mar 08 '13 at 11:06

1 Answers1

0

I would approach this a little bit differently:

  • Take some of the known values (wikipedia has a table)
  • if you take them, you could assume* they have uniform distribution
  • scale the results to your range, e.g. rnd()*52 / m + 1 and take that as an output

    *just keep in mind, "when you assume, you make ass out of U and Me" ;)

GiM
  • 460
  • 4
  • 13