modularised random number generation