qrand() is thread safe.  Also, why is this random at all?