a function to create a random integer in [0, n)