Use local random number generator, since rand() uses a lock