[Scottish] allowing a large newborn sea-mammal to collide with a rocky planetoid object devoid of atmosphere somewhere in another galaxy
wee question (to replace the pin-drop jokes :-) ) : program in C under Unix. Is there any way to get the time in tenth or hundredth of seconds ? Or to phrase it differently : i need a random number generator that won't give the same sequence of numbers every time that the seed is reinitialised in the same second (by 2 different users) srand(time(NULL)) and then rand() doesn't work. Or a different kind of seed ? Suggestions are welcome (should be readily available in your standard Unix system) Thanks, Elise *** This email and any accompanying files are confidential. If you are not the intended recipient you must not use, copy or disclose the content. If you have received this email in error please contact the sender by return email and delete this message. Thankyou for your co-operation. * ___ Scottish mailing list [EMAIL PROTECTED] http://mailman.lug.org.uk/mailman/listinfo/scottish
Re: [Scottish] allowing a large newborn sea-mammal to collide witha rocky plane toid object devoid of atmosphere somewhere in another galaxy
On Thu, 2003-03-20 at 11:56, Huard, Elise - D C&W Consultant wrote: > wee question (to replace the pin-drop jokes :-) ) : > program in C under Unix. > Is there any way to get the time in tenth or hundredth of seconds ? > Or to phrase it differently : i need a random number generator that won't > give the same sequence of numbers every time that the seed is reinitialised > in the same second (by 2 different users) > srand(time(NULL)) > and then rand() > doesn't work. > Or a different kind of seed ? Suggestions are welcome (should be readily > available in your standard Unix system) > Thanks, > > Elise > *** Read some entropy from /dev/urandom ___ Scottish mailing list [EMAIL PROTECTED] http://mailman.lug.org.uk/mailman/listinfo/scottish
Re: [Scottish] Auric Aorta ..
On Thu, 20 Mar 2003, Huard, Elise - D C&W Consultant wrote: > wee question (to replace the pin-drop jokes :-) ) : Going a touch Picasso there ? ;) > program in C under Unix. > Is there any way to get the time in tenth or hundredth of seconds ? > Or to phrase it differently : i need a random number generator that won't > give the same sequence of numbers every time that the seed is reinitialised > in the same second (by 2 different users) > srand(time(NULL)) > and then rand() > doesn't work. > Or a different kind of seed ? Suggestions are welcome (should be readily > available in your standard Unix system) Well, getting tenth or hundredth of seconds doesn't solve your problem; you just make the race-condition finer-grained. Two users could still get the same seed, its just less likely. For example, a user starts two instances of the program (deliberate or accident), both wait on a common synchronising signal (network packet?) you wouldn't believe how often these things happen So when it *does* happen (and presumably something nasty happens as a consequence), it will appear more bizarre and take longer to debug what when wrong. The way to make sure two users don't get the same seed is to have some concept of a seed-server. The simplest thing would be a file somewhere with an integer stored inside. Suitable file-locking should prevent multiple people accessing the file at the same time and if all the seed-server-clients know to increment the integer, your fine. More sophisticated solutions are possible, but that's probably good enough if you have full control of the clients. The other alternative is not to use rand(). The implementations tend to be linear congruential generators, which have a checkered history. The GNU ones used in Linux are ok, AFAIK; although they probably suffer from the same problems of correlations in higher dimensions discussed in: http://lib-www.lanl.gov/numerical/bookcpdf/c7-1.pdf (yes, I know it NRC again, but its a reasonable introduction ;) Alternative is to use /dev/random (or /dev/urandom depending on what you want). I don't know if this is on a standard Unix system, but what *is* a "standard Unix system" anyway? ;) HTH Paul. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Particle Physics (Theory & Experimental) GroupsDr Paul Millar Department of Physics and Astronomy [EMAIL PROTECTED] University of Glasgow [EMAIL PROTECTED] Glasgow, G12 8QQ, Scotland http://www.astro.gla.ac.uk/users/paulm +44 (0)141 330 4717A54C A9FC 6A77 1664 2E4E 90E3 FFD2 704B BF0F 03E9 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ___ Scottish mailing list [EMAIL PROTECTED] http://mailman.lug.org.uk/mailman/listinfo/scottish
Re: [Scottish] allowing a large newborn sea-mammal to collide witha rocky plane toid object devoid of atmosphere somewhere in anothergalaxy
> "Elise" == Elise Huard writes: Elise> Is there any way to get the time in tenth Elise> or hundredth of seconds ? gettimeofday(2) -- Right now, there are scr1pt k1dd13s plotting to DDoS my network, my co-lo server is not responding to pings and the people that I IRC with may be involved in both. I'm sysadmin Graeme Mathieson and this is the longest day of my life. http://www.wossname.org.uk/~mathie/ ___ Scottish mailing list [EMAIL PROTECTED] http://mailman.lug.org.uk/mailman/listinfo/scottish
Re: [Scottish] allowing a large newborn sea-mammal to collide witha rocky plane toid object devoid of atmosphere somewhere in another galaxy
Gordon JC Pearce wrote: On Thu, 2003-03-20 at 11:56, Huard, Elise - D C&W Consultant wrote: wee question (to replace the pin-drop jokes :-) ) : program in C under Unix. Is there any way to get the time in tenth or hundredth of seconds ? Or to phrase it differently : i need a random number generator that won't give the same sequence of numbers every time that the seed is reinitialised in the same second (by 2 different users) srand(time(NULL)) and then rand() doesn't work. Or a different kind of seed ? Suggestions are welcome (should be readily available in your standard Unix system) Thanks, Elise *** Read some entropy from /dev/urandom which isn't available on all flavours of Unix (e.g. Solaris up to v8). To solve this problem for cryptographic purposes, some brainy person wrote egd. This however requires 'input' to generate random numbers - and I don't no where to find it. A quick search on Freshmeat did turn up PRNGD (http://freshmeat.net/projects/prngd/?topic_id=44%2C136) which works in a similar manner to EGD and might suit your purposes. Although I'm happy to be proved wrong, I don't know of a portable method of measuring sub-1second time on Unix. The usleep function seems to be fairly std as does clock, but not ideally suited to what you are doing. ...or the kludgy solution which is to create a hash of the time + PID + UID and seed the generator with that. HTH Colin ___ Scottish mailing list [EMAIL PROTECTED] http://mailman.lug.org.uk/mailman/listinfo/scottish
RE: [Scottish] Auric Aorta ..
On Thu, 20 Mar 2003, Huard, Elise - D C&W Consultant wrote: > wee question (to replace the pin-drop jokes :-) ) : Going a touch Picasso there ? ;) No, 'Hitchhiker's guide to the galaxy ' (where a baby whale collides with planet Maghrateb, if i'm not mistaken) :-) Thanks for your suggestions , Gordon, Paul, Graeme and Collin, it definitely helps. *** This email and any accompanying files are confidential. If you are not the intended recipient you must not use, copy or disclose the content. If you have received this email in error please contact the sender by return email and delete this message. Thankyou for your co-operation. * ___ Scottish mailing list [EMAIL PROTECTED] http://mailman.lug.org.uk/mailman/listinfo/scottish
RE: [Scottish] Auric Aorta ..
On Thu, 20 Mar 2003, Huard, Elise - D C&W Consultant wrote: > On Thu, 20 Mar 2003, Huard, Elise - D C&W Consultant wrote: > > wee question (to replace the pin-drop jokes :-) ) : > > Going a touch Picasso there ? ;) > > No, 'Hitchhiker's guide to the galaxy ' (where a baby whale collides with > planet Maghrateb, if i'm not mistaken) :-) Yep, only slightly out ("Magrathea"), hence the Subject field (hint: the ship's name was Heart of Gold :^) ... oh dear, I really ought to get out more. The Picasso ref. was because your smilie and the closing bracket and colon made a somewhat dis-jointed Picasso-esque super-smilie :) .'^) ^_'^) > Thanks for your suggestions , Gordon, Paul, Graeme and Collin, > it definitely helps. Good luck! Cheers, Paul. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Particle Physics (Theory & Experimental) GroupsDr Paul Millar Department of Physics and Astronomy [EMAIL PROTECTED] University of Glasgow [EMAIL PROTECTED] Glasgow, G12 8QQ, Scotland http://www.astro.gla.ac.uk/users/paulm +44 (0)141 330 4717A54C A9FC 6A77 1664 2E4E 90E3 FFD2 704B BF0F 03E9 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ___ Scottish mailing list [EMAIL PROTECTED] http://mailman.lug.org.uk/mailman/listinfo/scottish