#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<cstdlib>
#include<ctime>
int hord(int);
int main()
{
int n;
cout<<"Length of maze:";
cin>>n;
for(int i=0;i<=n;i++)
{
for(int j=0;j<n;j++)
{
srand(time(0)); //Problem is here
int random=hord(j);
cout<<((random%2)? "#" : ".");
}
cout<<endl;
}
cin.get();
return main();
}
int hord(int)
{
int p;
p=1+rand()%10;
return p;
}
The random generator is seeded in every iteration of the inner loop, but each iteration takes a time << 1 second (I don't know the actual amount but it's just very small), so time(0) is very likely to be the same over all the iterations, and thus rand() gives you the same thing.