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 144
 {
145 145
 	int pid, child_process_no;
146 146
 	int ret;
147
+	unsigned int new_seed1;
148
+	unsigned int new_seed2;
147 149
 #ifdef USE_TCP
148 150
 	int sockfd[2];
149 151
 #endif
... ...
@@ -181,6 +184,8 @@ int fork_process(int child_id, char *desc, int make_sock)
181 181
 	
182 182
 	
183 183
 	child_process_no = *process_count;
184
+	new_seed1=rand();
185
+	new_seed2=random();
184 186
 	pid = fork();
185 187
 	if (pid<0) {
186 188
 		lock_release(process_lock);
... ...
@@ -190,6 +195,8 @@ int fork_process(int child_id, char *desc, int make_sock)
190 190
 		/* child */
191 191
 		is_main=0; /* a forked process cannot be the "main" one */
192 192
 		process_no=child_process_no;
193
+		srand(new_seed1);
194
+		srandom(new_seed2+time(0));
193 195
 #ifdef PROFILING
194 196
 		monstartup((u_long) &_start, (u_long) &etext);
195 197
 #endif
... ...
@@ -265,6 +272,8 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
265 265
 	int sockfd[2];
266 266
 	int reader_fd[2]; /* for comm. with the tcp children read  */
267 267
 	int ret;
268
+	unsigned int new_seed1;
269
+	unsigned int new_seed2;
268 270
 	
269 271
 	/* init */
270 272
 	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 308
 	
309 309
 	
310 310
 	child_process_no = *process_count;
311
+	new_seed1=rand();
312
+	new_seed2=random();
311 313
 	pid = fork();
312 314
 	if (pid<0) {
313 315
 		lock_release(process_lock);
... ...
@@ -317,6 +328,8 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
317 317
 	if (pid==0){
318 318
 		is_main=0; /* a forked process cannot be the "main" one */
319 319
 		process_no=child_process_no;
320
+		srand(new_seed1);
321
+		srandom(new_seed2+time(0));
320 322
 #ifdef PROFILING
321 323
 		monstartup((u_long) &_start, (u_long) &etext);
322 324
 #endif