The following exercises provide you with the opportunity to practice with Monte Carlo algorithms. The solutions to these exercises are found in the section .
Say that we have a large array of integers, and we want to determine what percentage of the integers are even and what percentage are odd. Write code that performs random sampling to approximate these percentages.
Let’s say that I ran The Formula from Fermat’s Primality Test on an integer N a total of four times. Three times the result was 1, and one time the result was 2. What are the odds that N is prime?
Now, let’s say that I ran The Formula from Fermat’s Primality Test on an integer N a total of four times, and all four times the result was 1. What are the odds that N is prime?