I am new to c++. I wrote a function which returns a random array, but when I ran this function in a for loop, this only give the same array. Please help me.
#include <iostream>
#include<headers.h>
#include<cstdlib>
#include <ctime>
#include<stdlib.h>
#include<math.h>
using namespace std;
int * getRandom( ) {
static int r[8];
int inicio = 0;
int fin = 7;
// set the seed
srand( (unsigned)time( NULL ) );
for (int i = 0; i < 8; ++i) {
r[i] = rand()%8;
}
return r;
}
int main()
{
int *r;
r = getRandom();
int *p = NULL;
for(int i=0; i<10; i++){
p = getRandom();
cout<<"--------"<<endl;
for(int j=0; j<8; j++){
cout<<p[j];
}
cout<<endl<<"--------"<<endl;
}
return 0;
}