Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Median/Mode in arrays? {Need help} Java|Tera Java 27 Nov 29th, 2005 11:50 AM
FiveDigit + RandomeNumber Game. TecBrain Java 0 Nov 18th, 2005 3:53 PM
Random Number & Average Problem Hadrurus Java 6 Aug 15th, 2005 2:08 PM
generate a random number cwl157 Java 3 Apr 15th, 2005 7:18 PM
non repeating random number generation gencor45 C# 2 Feb 9th, 2005 1:11 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:37 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC