In order to create the spiral, prime numbers must first be identified. One way to do this is to use a sieve. A simple and efficient (for small values) sieve is the classic "Sieve of Eratosthenes", named after the Greek mathemetician Eratosthenes to whom the sieve was attributed.
As shown above (image from Wikimedia Commons), the idea behind the sieve is to incrementally eliminate all multiples less than n -- the upper bound of the number set. The remaining numbers have no factors and are then prime.