AKA Panama Jack wrote:Hockey wrote:I don't think either are as unique or accurate as a CPU tick count
I think the potential for overlap using either is likely as it is using just time() as microtime() just returns time in milliseconds...
I have to go either tick count or random character generation...
I'm thinking random character generation would be best...
The likelyhood that two people access the site at the same time will get the exact same microtime result is
millions to one. We are talking one millionth of a second increments here.
First off...it just dawned on me...that microtime returned time in micro seconds NOT milli seconds...which was the reason I expressed dought in the first place...
But...I'll explain my reasoning...perhaps incorrect...but I'll explain anyways so everyone understands where I'm coming from and doesn't think I'm just an idiot...
It's been a long time since I've done any assembler or read anything of that nature...so don't quote me on anything...but...
A 950Mhz processor like my AMD950 clocks at 950 million cycles/second
Every statement in PHP is converted into a high level byte code which is then passed to an interpreter, which then basically executes the machine specific instruction(s) to carry out that task. Every machines instruction set is different from the next...some machines have instructions which only expend a few cycles and other instructions consume more than a dozen.
For instance consider the x86 familiy of processors and the very popular MOV instruction.
286/386 used 2 clock cycles whereas the 486 used only one.
Basically what this says to me is: 950 million cycles/second equals 950 million MOV instructions in one second on a 486 or 475 million on 286/386...
Now lets assume for the sake of arguing that:
Results in approximately 300 instructions, each of which consumes 10 cycles...
on my AMD950 that is only 3000 cycles which leaves: 949997000 cycles unused in one second, so in one second my AMD950 could execute the above code snippet:
316666.66666666666666666666666667 times in one second!!!
This calculation assumes were using only the raw resources of the CPU and there is no OS or PHP scripts/interpreters, and other processes, etc...
What this says to me, is that under an ideal situation, where our required instructions for the above PHP code snippet results in 300 instructions at 10 clock cycles each...what this means IMHO...is that:
Could execute
316666 times in
one second that's alot of times to execute code in one second...
The point is...if this is true...
mktime, time, microtime, etc...all return the "time" at current execution but the above calculation tells me that
microtime could be called 316666 times in one second...that means...
Let me think here...i'm starting to loose myself
Thus the reason I wanted a cycle count as opposed to microtime...cycle counts, like that returned by Intels
Read Time Stamp Counter return the number of cycles expended since bootup...
This *is* guaranteed to be unique everytime you check it...as calling the RDTSC instruction needs to be invoked at a minimum and thus uses clock cycles...
So yea...it should always be unique
Now, again, this assumes an ideal working environment...no OS doing any fancy task switching, etc...but consider this...
Although I was incorrect in thinking microtime was returning milliseconds not microseconds...

even microseconds, on machines which are capable of performing in the nanoseconds and even faster with time to come...I was just trying to give my code a consistent gauantee of uniqueness...at least on single processor machines anyways
It's obvious to me now...I will likely just stick with randomized characters and hope for the best
Cheers
