Refactor random functions