Added rand variable
Fixed time function