Browse code

- random number are seeded in all the processes (both srand() and srandom())

Andrei Pelinescu-Onciul authored on 28/11/2006 19:04:54
Showing 3 changed files
... ...
@@ -67,7 +67,7 @@ MAIN_NAME=ser
67 67
 VERSION = 0
68 68
 PATCHLEVEL = 10
69 69
 SUBLEVEL =   99
70
-EXTRAVERSION = -dev61
70
+EXTRAVERSION = -dev62
71 71
 
72 72
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
73 73
 			$(SUBLEVEL) )
... ...
@@ -1271,6 +1271,7 @@ try_again:
1271 1271
 	seed+=getpid()+time(0);
1272 1272
 	DBG("seeding PRNG with %u\n", seed);
1273 1273
 	srand(seed);
1274
+	srandom(rand()+time(0));
1274 1275
 	DBG("test random number %u\n", rand());
1275 1276
 
1276 1277
 	/*register builtin  modules*/
... ...
@@ -43,6 +43,7 @@
43 43
 #include "sr_module.h"
44 44
 
45 45
 #include <stdio.h>
46
+#include <time.h> /* time(), used to initialize random numbers */
46 47
 
47 48
 #define FORK_DONT_WAIT  /* child doesn't wait for parent before starting 
48 49
 						   => faster startup, but the child should not assume
... ...
@@ -144,6 +145,8 @@ int fork_process(int child_id, char *desc, int make_sock)
144 145
 {
145 146
 	int pid, child_process_no;
146 147
 	int ret;
148
+	unsigned int new_seed1;
149
+	unsigned int new_seed2;
147 150
 #ifdef USE_TCP
148 151
 	int sockfd[2];
149 152
 #endif
... ...
@@ -181,6 +184,8 @@ int fork_process(int child_id, char *desc, int make_sock)
181 184
 	
182 185
 	
183 186
 	child_process_no = *process_count;
187
+	new_seed1=rand();
188
+	new_seed2=random();
184 189
 	pid = fork();
185 190
 	if (pid<0) {
186 191
 		lock_release(process_lock);
... ...
@@ -190,6 +195,8 @@ int fork_process(int child_id, char *desc, int make_sock)
190 195
 		/* child */
191 196
 		is_main=0; /* a forked process cannot be the "main" one */
192 197
 		process_no=child_process_no;
198
+		srand(new_seed1);
199
+		srandom(new_seed2+time(0));
193 200
 #ifdef PROFILING
194 201
 		monstartup((u_long) &_start, (u_long) &etext);
195 202
 #endif
... ...
@@ -265,6 +272,8 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
265 272
 	int sockfd[2];
266 273
 	int reader_fd[2]; /* for comm. with the tcp children read  */
267 274
 	int ret;
275
+	unsigned int new_seed1;
276
+	unsigned int new_seed2;
268 277
 	
269 278
 	/* init */
270 279
 	sockfd[0]=sockfd[1]=-1;
... ...
@@ -308,6 +317,8 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
308 317
 	
309 318
 	
310 319
 	child_process_no = *process_count;
320
+	new_seed1=rand();
321
+	new_seed2=random();
311 322
 	pid = fork();
312 323
 	if (pid<0) {
313 324
 		lock_release(process_lock);
... ...
@@ -317,6 +328,8 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
317 328
 	if (pid==0){
318 329
 		is_main=0; /* a forked process cannot be the "main" one */
319 330
 		process_no=child_process_no;
331
+		srand(new_seed1);
332
+		srandom(new_seed2+time(0));
320 333
 #ifdef PROFILING
321 334
 		monstartup((u_long) &_start, (u_long) &etext);
322 335
 #endif