Thread local random number generator. Copied from librand.