Refactors random generation logic (2)