...hmmm... and now we may have an argument for using microtime...
If you've moved away from staying pure Perl, for a source of an unguessable counter, I'd use the Time Stamp Counter.
Given that this changes by anything ranging from 1/2 a million to 10s of millions between successive calls in a tight loop, the odds of collisions even if you have 16 concurrent cores are negligible:
#! perl -slw use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'rdtsc', CLEAN_AFTER_BUILD => 0; SV *rdtsc() { return newSVuv( (UV)__rdtsc() ); } END_C my( $last, $this ) = ( 0, 0 ); print( $this = rdtsc(), ' ', $this - $last ), $last = $this for 1 .. +20; __END__ C:\test>rdtsc 95054001389914 95054001389914 95054002276396 886482 95054003052862 776466 95054004698944 1646082 95054006658865 1959921 95054008588537 1929672 95054010420586 1832049 95054012410180 1989594 95054014268572 1858392 95054016253981 1985409 95054018070946 1816965 95054050803874 32732928 95054051382070 578196 95054053061884 1679814 95054054901610 1839726 95054056870252 1968642 95054058682825 1812573 95054060659909 1977084 95054062399501 1739592 95054064304702 1905201
Indeed, used alone with some suitable modulus operations, it would form the basis of a pretty damn good cryptographic rand() all by itself.
Even if the bad guys had an identical system -- hardware and software -- it would be impossible to predict the next number coming from it. It is affected by every single thing that happens on the system -- interrupts from your nic; mouse movements; thermal loading; every piece of software running in the systems.
Even if you put two totally identical systems side by side and synchronised them, I bet they would not stay in step for more than a few milliseconds.
In reply to Re^3: How do I get a unique Perl Interpreter ID?
by BrowserUk
in thread How do I get a unique Perl Interpreter ID?
by wrog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |