| Generates a unique ID composed of printable characters. 24 characters
are quasi-base-64-encoded from 18 random bytes
generated by a good (in this case java.util.SecureRandom) random number
generator. In case anyone is worried about the possibilities of collision
of these IDs over time, the formula for probability of non-collision is
$p = e^{-n^2/2k}$. Inverting and approximating for small p we gain
$n = \sqrt{2k/p}$. For 144 bits of hash (~ 10^43), if we ask how many
pages (resources) must be generated before the probability of collision
reaches 1 in a billion (10^-9), we require ~ 10^17 hashes, i.e. 200Pb of
pages if only one byte per page.
This class is threadsafe, at the moment since SecureRandom is synchronized.
author: Antranig Basman (antranig@caret.cam.ac.uk) |