WIP: use re-entrant rand_r