I have written a random number generator using srand(), which creates an array of random numbers of given size. I would like my random numbers take values up to 1000.000 and to get this, I've defined each entry of the array as rand()%1000000 in the code below. The wierd thing is that, the random values are all up to around 30.000 and bigger random numbers such as 987.623 are not created i.e. the digit count of the random numbers are not more than 5.
Anyone have any idea of why is this happening? Is there another way (function) that you can offer to get random numbers biggers than these ones?
#include <iostream>
#include <fstream>
#include<stdlib.h>
#include <time.h>
#include <cmath>
#include <vector>
using namespace std;
int * rng(int size) {
int* a=NULL;
a=new int[size];
for (int i=0; i<size; i++)
{ a[i] = rand()%1000000;
if (a[i] ==0)
{ a[i]+=1;}
}
for (int j=0;j<size;j++)
{cout<<a[j]<<" ";}
return a;
delete [] a;
a = NULL;
}
Aucun commentaire:
Enregistrer un commentaire