Why the sequence isn't random?

Hi,
I have a function gen_graph() which calls the rand() function to generate number sequence and output the sequence into a file, and my main function has such a structure:
1
2
3
4
5
6
7
8
9
10
int main()
{
  srand( time( 0 ) );
  for( size_t i = 0 ; i != 100 ; ++i )
  {
    ...
    gen_gdraph();
    ...
  }
}

after execution, i got 100 files, but all the files are exactly the same!!! Why?
How can i get 100 different files? Thanks.
closed account (z05DSL3A)
akilguo wrote:
I have a function gen_graph() which calls the rand() function to generate number sequence
It would help if you posted the code that is meant to generate the pseudo random numbers.
the code of gen_graph is as following:
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
size_t gen_edge( size_t &row, size_t& column, size_t verNum, size_t *pt )
{	
	size_t v1, v2;
	v1 = rand() % verNum;
	v2 = rand() % verNum;

	return pt[ row * ( row - 1 ) / 2 + column ] ;
}


void gen_graph( size_t verNum, size_t egNum,ofstream & os )
{
	size_t row, column ;
        size_t *pmtrx = ...;
	...
	for( size_t i = 0 ; i != egNum ; ++i )
	{
		while( gen_edge( row, column, verNum,pmtrx ) );
		...
	}
	...
}

int main()
{
	srand( time( 0 ) );
	for( size_t i = 0 ; i != 100 ; ++i )
	{
		...
		gen_graph( 100,4000,outfile );
                ...
	}
	return 0 ;
}
Last edited on
Topic archived. No new replies allowed.