mardi 17 février 2015

How to pick up some random elements in an array

in Hnode function I want to randomly choose 40 elements from the output of SNode function that contains 50 elements. But i got this error in SNode function : 'int[int]' for array subscript


I invoked SNode function in Hnode. and i want to use the output of that functin



int HNode::database(int chunk_var)
{
SNode::database(chunk_var);
size=40;
chunk_var = chunk_var[ rand() % size ]; // Here i got error
return chunk_var ;
}


Snode was supposed to make an array with 50 elements:



int SNode::database(int chunk_var)
{
int array[50];
srand ( time(0) );
for(int j = 0; j<50 ;j++)
{
int myrand = rand() % 2 ;
myrand = myrand & 0x3ff;
array[j]= myrand;
chunk_var = array[j];
}
return chunk_var;
}


how can i get ride of this error?





Aucun commentaire:

Enregistrer un commentaire