lundi 5 janvier 2015

generate random float in for loop

I have a very simple for loop to generate some random float numbers:



int dim = 6;
int n = 100000;

int size = n * dim;

float data[size],r;
for(int i = 0; i < size; i++)
{
r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
data[i] = r;
}


It works fine until i increase the size of the n from 100000 to 1000000. Here is the full code on ideone: http://ift.tt/14dwdKv


Actually on my computer it works only with n=10000. Any bigger number causes a crash. No error message.





Aucun commentaire:

Enregistrer un commentaire