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