Replace calls to rand() by calls to rand_r() in the scheduler Implements #302 using @d74ksy's changes. See merge request !405