At the beginning the script creates a random number. Than it tries to "guess" that number by creating another random number in a loop. If the too numbers match the loop ends and the script displays the number of attempts.