optimize rand number generator