WIP: revert use of rand_r