I write a piece of software that runs inside banner ads which generates millions of session IDs every day. For a long time I've known that the random number generator in Flash is't random enough to generate sufficiently unique IDs, so I've employed a number of tricks to get even more random numbers. However, in ActionScript 2.0 it's not easy, and I'm seeing more and more collisions, so I wonder if there is something I've overlooked.
As far as I can tell the problem with Math.random()
is that it's seeded by the system time, and when you have sufficient numbers of simultaneous attempts there are quite a few collisions.
In ActionScript 3.0 I use the value returned by System.totalMemory
as a bit of extra randomness, but there's no equivalent in ActionScript 2.0. AS3 also has Font.enumerateFonts
, and a few other things that are different from system to system.
What I need isn't something perfectly random, just something that is random enough to dilute the randomness I get from Math.random()
. Think of it this way: there is a certain chance that two people will generate the same random number sequence using only Math.random()
, but the chance of two people generating the same sequence and having, say, the exact same list of fonts is significantly lower.
I cannot rely on having sufficient script access to use ExternalInterface
to get hold of things like the user agent, or the URL of the page. I don't need suggestions of how to do it in AS3, or any other system, or server side, only AS2 -- using only what's available in the standard APIs.
On the server side I also add the IP address to the session ID, but even that isn't enough (for example, many large companies use a single proxy server and that means that thousands of people all have the same IP -- and since they tend to look at the same sites, with the same ads, roughly at the same time, there are many session ID collisions). Doing more on the server side is, for various reasons, not practical. I can, for example, not generate random numbers on the server side and send them to the client, even if I very much would like to be able to solve it that way.
The best I've come up with so far is to use the list of microphones (Microphone.names
), but I've also tried to make some fingerprinting using some of the properties in System.capabilities
, I'm not sure how much randomness I can get out of that though so I'm not using that at the moment. I hope I've overlooked something.
I'm sorry to come off as arrogant in my comments to your answers, but please, if you don't know ActionScript 2.0, or know how a pseudo random number generator works, don't try to answer, it won't help and I will give downvotes. I really appreciate proper answers, though.