mercredi 30 novembre 2016

for loop is crashing on big number

I have a problem. I have to write a program that counts the collisions of the table of randomly generated numbers(collision test). For example table [1,2,2,3,4,5,5,5,6] has 3 collisions. Here is my code: And my problem is that whenever i try to increase number n to for example int n = 5191401 my program crashes. What is happening? Why does it stop working? I need really big ammount of random numbers (like 10^14)

    #include <iostream>
    #include <gsl/gsl_rng.h>
    #include <stdlib.h>
    #include<cmath>
    using namespace std;
    int compare(const void * a, const void * b){
    return ( *(int*)a - *(int*)b );
    }
   int main (void)
   {
unsigned int seed=10540000;
gsl_rng * r=gsl_rng_alloc (gsl_rng_minstd);
gsl_rng_set(r,seed);
gsl_rng_env_setup();
int lPrzedzialow=400000000;
int n = 519140;
int z,lKolizji=0;
int lwKomorkach[n-1];
double dlPrzedzialu=1./(lPrzedzialow);
for (int i = 0; i < n; i++)
{
    lwKomorkach[i]=floor(gsl_rng_uniform (r)/dlPrzedzialu)+1;

}
qsort (lwKomorkach, n, sizeof(int), compare);
for(z=0;z<=n-1;z++)
{
        if(lwKomorkach[z+1]==lwKomorkach[z]){lKolizji++;}
}
cout<<endl<<lKolizji<<endl;
gsl_rng_free (r);
return 0;
}




Aucun commentaire:

Enregistrer un commentaire