osrandom engine fix backported from master

This is an identical changeset to #660.