ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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
seed ( getpid() ^ time() );
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.