PDA

View Full Version : Random Seed Problem



xman
08-01-2002, 08:53 AM
Howard, is it possible to let us specify the random seed ? instead of using the time of the machines. I usually start all my machines using script. Thus, they are started within a few seconds, and they have identical values written into the lock file, as I track the files manually. Moreover, the pid used by some of the machines with same starting time, are the same. So I suppose they are working on identical set of data.

Thus, I'm asking for option to specify the seed such that we might able to avoid the duplication of computation.

Or may be you have other methods to avoid that. Please suggest.

IronBits
08-01-2002, 09:55 AM
Use the utility called SLEEP in your script. After starting one computer, make it SLEEP for 5 seconds before starting the next one...

xman
08-01-2002, 09:57 AM
I have tried using 5 seconds to 10 seconds ... Still cannot avoid duplication. Too bad.

Brian the Fist
08-01-2002, 10:20 AM
1) The random seed is not the time, it combines time and PID

2) PID (which is written to the lock file) is a UNIQUE number on all POSIX OSes and even Windows.
It is extremely unlikely that two machines will assign the same PID at the same second of time.
I have over 150 CPUs that I start all simultaneously so don't try to convince me that you know better ;)

wirthi
08-01-2002, 10:40 AM
What about additionally using the IP-address?

xman
08-01-2002, 11:36 AM
I see. I thought the lock file is the starting time related value. However, i grabbed all the lock files in each machine, and found duplicated pid. Just that they might be started at different time. But, if the starting time is short, they as well may be started at the same second.

And how do you explain the same pid i got from some of the lock files ? Because the machines are clone of each other ?

collin
08-01-2002, 12:02 PM
I'm not convincing you that I know better ;p, but I'm observing the numbers in the .lock file to be fairly close to each other on my NT/2K/XP boxes which are running as services. These numbers look suspiciously like process ID numbers on these boxes. And assuming they are, it is not so incredible that 2 boxes will share the same process ID, and that both boxes are not completely time-synchronised when you start those processes at such close (regular) intervals with each other.

FWIW, the numbers in the .lock file for W9X variants do spread out pretty randomly.

bwkaz
08-01-2002, 03:20 PM
Could you test for the existence of /dev/random and use some chunk of entropy from it if it's there (I'd guess you probably wouldn't need the full amount of entropy from the kernel pool, more like 1 or 2 bytes of it)?

Obviously that won't help on Windows, but most Unixes (AFAIK) have that device file.

-------

PIDs are indeed unique per-kernel. But if you're running some kind of loosely-coupled system (separate boxes connected with Ethernet), and if there aren't any shared kernels floating around (usually there aren't; it's hard to share memory over Ethernet), then the PIDs will still be unique per-kernel (per-box), but it's possible that if two instances are started at the same "relative time" (the same time relative to all other processes on the box; for example, if all foldit processes were started 312'th in order), then as far as I've seen, they'll all have the same PID, in this case, 312. From what I've seen, Linux at least assigns PIDs sequentially.

One solution for the original poster would be to sleep 1 (5 would work also, but it'd take a loooong time to start up all the clients; 1 second should be more than enough time to sleep) in between startups. That way, the random seeds will be different. They will still be close to each other, but with the way libc's pseudorandom-number generator works, the random numbers themselves should be very different once a couple have been generated.

Scoofy12
08-01-2002, 07:06 PM
As i guess howard just said, th value written to the lock file is the PID, which Linux assigns sequentially, so if you have DF in your startup script I'd believe you could get the same PID on different boxes if they are all clones. To get the same random seed you'd have to boot all of your PCs simultaneously though. Alternately you could write a script to use ssh or some other such thing to start your DF clients "manually" rather than on startup, one by one. That way they won't be started in the same second of time.

xman
08-01-2002, 10:59 PM
OK. Thanks for replying. Well, even with different seed numbers, we cant prove that there is no duplication, because random function with different seed numbers may as well generate some identical output. But I think this is not a significant issues. So, let's forget about this thread.