added random number generator and averaging of multiple runs