This example uses the random() function to quickly simulate behavior within a range. In this case, the…