random number generation logic