Gap test- assume we have 3 numbers and the sequences is 1 2 3 2 1 3 1 3 2 1 2 3 2 1 3. for the 1s gaps are 3 1 2 3 In theory for gap of length 3 is p(no 1)p(no 1)p(no 1)p(1)= 2/3*2/3*2/3*1/3 So a probability for n different types of things of gap k is (n-1/n)(k-1) (1/n) So probability of gaps less than k is sum( from i=1 to k-1) (n-1/n)(i-1) (1/n) = 1 - ((n-1)/n)^(k+1) Algorithm (1) Specify the theoretical frequency- for dice set n=6 (2) Arrange the observed sample of gaps in a cumulative distribution (3) Find maximum deviation from theory Look at Table How do we generate numbers for other distributions: For exponential distribution , the pdf is f(x) = a* exp(-a *x) for x>0 and 0 otherwise where 1/a is the mean interarrival time. The CDF is the integral of the pdf and for x>0 it is F = 1- exp(-a*x) for the exponential. To generate random numbers it is best if one can find the inverse of the CDF Let R =1- exp(-a*x) , a random number in the range of (0 to 1) Then exp(-a*x) = 1-R -ax = ln(1-R) x= -1/a ln(1-R) Therefore generate a random number R, and then find x the random number in the distribution from the formula x= -1/a ln(1-R) Since in a uniform distribution the probability of R and 1-R are the same , we usually use x = -1/a ln (R) Let's set a=1 for simplicity. Pick R(1), a random number in the uniform distribution. It corresponds to X(1) =- ln(1-R(1)). P( x #include #include int main() { int save; int i, place; double r, x; int count[11]={0}; for ( i=0;i<1000;i++) { r=1.0*rand()/RAND_MAX; x=-log(r); place=x*10; cout <2 Given R set z = sqrt(2R) for 0