• Welcome to the new Internet Infidels Discussion Board, formerly Talk Freethought.

A Problem In Random Numbers

steve_bank

Diabetic retinopathy and poor eyesight. Typos ...
Joined
Nov 9, 2017
Messages
14,733
Location
seattle
Basic Beliefs
secular-skeptic
One of the tests to evaluate a random number generator is the gap test. For a uniform distribution of integers 0-100 for a given number the gaps between occurrences of the number are found and the cumulative distribution is plotted.

I would have thought the distribution would have been normal or uniform as a guess, but it is exponential.

I do not know enough to directly work out why, a problem to chew on for somebody with better math.

Given a uniformly random distribution of integers length n derive why the di9stribution of distances between occurrences of a single number is exponentially distributed.

Solution would be an exponential distribution p(x) = (1/average)*e^(-x/average)

The code uses the C++ built in mt19937 generator.

Gnuplot cd.plt
set term windows background rgb "white" title "SIGNALS" fontscale 1
reset
set grid lt 1 lw 1 lc rgb "black" dashtype solid
set yrange[*:100]
set xrange[0:*]
plot 'gaps.txt' using 2:1 with lines ls 4 lt -1 lw 3
show grid

Code:
#include <random>

void gap_test(void){
   cout<<"gap test"<<endl;
  
   long long i,n = pow(10,7);
   double aver,median;
   int *y = new int[n];
   int *gaps = new int[100000];
    double *cd = new double[100000];
   int hi = 100,lo = 0;
   mt19937 rand_gen(time(NULL));
   uniform_int_distribution<unsigned int> dist (lo,hi);
   for(i=0;i<n;i++) y[i] = dist(rand_gen);

   int gap0,gap1,s = 0,ngaps=0;
   int delta,max =0,min = n;
    int num =33;
    for(i=0;i<n;i++){if(y[i]==num)gap0=i;break;}
    gap1 = gap0;

    for(i=gap0+1;i<n;i++){
        if(y[i] == num){
            delta = i-gap1;
            s += delta;
            if(delta > max)max = delta;
            if(delta<min)min = delta;
            gap1= i;
            gaps[ngaps] = delta;
            ngaps++;
            }
    }

    for(i=0;i<ngaps;i++)cd[i] = 100*double(i)/double(ngaps);
    sort(&gaps[0],&gaps[ngaps]);
    aver = double(s)/double(ngaps);
    printf("n gaps %d\n",ngaps);
    printf("number  %d lo  %d  hi  %d\n",num,lo,hi);
    printf("min gap %d  max gap  %d\n",min,max);
    printf("average gap  %f  median %f\n",aver,log(2)*aver);
    FILE *p = fopen("gap_test.txt","w");
    fprintf(p,"n gaps %d\n",ngaps);
    fprintf(p,"number  %d lo  %d  hi  %d\n",num,lo,hi);
    fprintf(p,"min gap %d  max gap  %d aver gap  %.5f\n",min,max,aver);
    fclose(p);
    p = fopen("gaps.txt","w");
    for(i=0;i<ngaps;i++)fprintf(p," %2.6f\t  %10d\n",cd[i],gaps[i]);
    fclose(p);
    system("cd.plt");
}
 
Last edited:
Cumulative distribution, gaps vs cumulative probability in percent . Given a number has occurred probability of the distance of the next occurrence. The probabiity of a single distance is the limit as dx goes to zero. Probability of a next distance of 200 is the limit as dx about 200 goes to zero.

1728335304315.pngu
 
Last edited:
After x, the next number will be x with probability 1/100 in the example, or not-x with probability p = 99/100.
A gap of size k+1 occurs with probability (1-p)⋅pk. This is the Exponential Distribution.
 
I don't remember how far back this was.

There was a concaveness propaganda campaign against national campaign. Fear mooring.

Canada as an example of national; health care was smeared with false claims, today Trump like conspiracy theories.

Socialism leading to communist and loss of freedoms.

The guy who orchestrated it eventually fessed up and said he made a mistake.

Medicare Advantage plans are a good model. I have had one for over 10 years.

The government gives Medicare money to private insurance companies to provide at least the minimum Medicare benefits. Insurance companies compete by adding benefits above Medicare.

The service from my United pan could not be better.

Plans run from zero premiums and up. My zero premium pan has dental benefits.
 
I don't remember how far back this was.

There was a concaveness propaganda campaign against national campaign. Fear mooring.

Canada as an example of national; health care was smeared with false claims, today Trump like conspiracy theories.

Socialism leading to communist and loss of freedoms.

The guy who orchestrated it eventually fessed up and said he made a mistake.

Medicare Advantage plans are a good model. I have had one for over 10 years.

The government gives Medicare money to private insurance companies to provide at least the minimum Medicare benefits. Insurance companies compete by adding benefits above Medicare.

The service from my United pan could not be better.

Plans run from zero premiums and up. My zero premium pan has dental benefits.
Are your premiums entirely random, or is this post in the wrong thread?
 
Back
Top Bottom