ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how can you even call a program 1000000 times per second?
bash, batch and C system and exec calls are all too slow.
the only way you could do it is if its from withen it self and in that case it would have the same PID.
If you XOR the PID, you don't have to use that type of time resolution.
I can't tell you why, but I like
Code:
seed ( getpid() ^ time() );
better than
Code:
seed( tv_sec * tv_usec (microseconds));
Moore's law ought to knock about 3 orders of magnitude off your safety factor there in 10 years, or 6 in 20. The first line of code will work just as well then as now. The second? I'll take your bet that I can't launch processes that fast in 10 years.
Having looked through the thread it would appear that the answer I was going to give to the original problem has already been given by Johnsfine.
However, the digression on how you seed the random numbers raises a few thoughts. To me I don't like the idea of using the PID because first it is not cross platform. I also like to keep a record of the seed so that the process can be recreated so I tend not to use time() either rather a variable that could be read in or derived (possibly from the time function). But basically if having "random numbers" is a critical element of a program then don't use the rand function but look for a means of getting true random numbers.
johnsfine was a little late This thread was started 4 years ago
Oops!
I didn't notice the fact that the thread was reopened with a different question, nor the dates on the earlier posts. I just saw that there seemed to be no answer posted for the original question.
I really wish the forum software would give some very visible indication when there is a giant jump in date between two successive posts in a thread.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.