View Single Post
Old Feb 6th, 2007, 6:01 AM   #1
programmingnoob
Hobbyist Programmer
 
Join Date: Feb 2006
Posts: 155
Rep Power: 3 programmingnoob is on a distinguished road
c-unix-childprocesses-random number

well, the parent process is supposed to fork out two child processes and each of the child process are supposed to come up with a random integer between 0 and 1 and do a lot of other things

however, each child process is supposed to do identical things, therefore, i wrote the same function (say functionc()) for both of them and just passed appropriate parameters to them. I am using rand () to come up with the random number in functionc()

[HTML]int choice = rand() % 2;[/HTML]


now the problem is both child process always come up with the same random number. In other words, either both child processes will come up with 1 or both child processes will come up with 0 ...
I am guessing part of the problem is they are using exactly identical memory images, so even the random number generator is generating the same number for both of them?

is there any way i fix that apart from writing different functions for both of them, which doesnt so sound sophiscated when both of them are supposed to do exactly same thing except come up with different random number occassionalyy
programmingnoob is offline   Reply With Quote