Fixed bug with randflag

As noted by jacques in hack-a-day comment.