fix random generation implementation