problem in acessing function

Hello again.i have some code to create a "#"&"." maze like

##...###
#.###...
.#####..
###..###

but my code only create
#####
#####
#####

or

.....
.....
.....
.....


whats the problem.why for(int j=0;j<n;j++) can acess hord(j) function for every value of j.

my code is here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#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;
}


Please help
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.

Seed the random generator outside the loops.
Topic archived. No new replies allowed.