Tag Archives: primes

Find random prime numbers in C#

The example Probabilistically determine whether a number is prime in C# explains an algorithm for determining whether a number is prime with any desired level of certainty. After you add that method to your algorithmic toolkit, finding large prime numbers … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , , | Leave a comment

Determine whether a number is prime in C#

This is a cool little algorithm that uses some clever mathematics. This algorithm and several related algorithms are described in my book Essential Algorithms: A Practical Approach to Computer Algorithms. I think it’s a really good book (and it’s gotten … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , , , , | 2 Comments

Use yield to generate prime numbers in C#

  This example is based on a lesson about interfaces that I recently recorded for O’Reilly Video Training.   This example shows how to use the yield return statement to generate prime numbers. More importantly it explains how yield return … Continue reading

Posted in algorithms, mathematics, syntax | Tagged , , , , , , , , , , , , , , | Leave a comment

Draw a colored fractal curve generated by prime numbers in C#

This example shows how to draw a colored fractal curve generated by prime numbers. See the example Draw a fractal curve generated by prime numbers in C# for the basic algorithm. This example assigns colors to line segments based on … Continue reading

Posted in algorithms, fractals, graphics, mathematics | Tagged , , , , , , , , , , , , , | Leave a comment

Draw a fractal curve generated by prime numbers in C#

This example shows how to draw a fractal curve generated by prime numbers. It’s a modification of the earlier example Draw a fractal generated by prime numbers in C#. The basic idea is follow these rules: Start at the point … Continue reading

Posted in algorithms, fractals, graphics, mathematics | Tagged , , , , , , , , , , , | 1 Comment

Use a bitmap to visualize composite runs in C#

I promise this is my last post on primes for a while. (Sometimes one example leads to another, which leads to another, and so on.) This example draws a bitmap to help visualize composite runs and prime numbers. The basic … Continue reading

Posted in algorithms, graphics, image processing, mathematics | Tagged , , , , , , , , , , , , , | Leave a comment

Find runs of composite numbers (non-primes) in C#

I recently had a birthday and my age is a prime number, so like any normal person I was wondering how long a run of consecutive composite numbers comes after my current age. (Doesn’t everyone wonder such things?) This example … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , | Leave a comment

Use a bitmap to visualize odd primes in C#

This example modifies the program in Use a bitmap to visualize primes in C# to let you visualize odd primes. It creates an is_prime array like the previous example does, but it makes the array twice as large as before. … Continue reading

Posted in algorithms, graphics, image processing, mathematics | Tagged , , , , , , , , , , , , , | 1 Comment

Use a bitmap to visualize primes in C#

This example makes a bitmap that helps you visualize primes. The example uses the techniques described in the post Use Euler’s Sieve to find prime numbers in C# to build a table of prime numbers. It then makes a bitmap … Continue reading

Posted in algorithms, graphics, image processing, mathematics | Tagged , , , , , , , , , , , , | 7 Comments

Use Euler’s Sieve to find prime numbers in C#

The Sieve of Eratosthenes is a simple way to make a list of prime numbers. The basic idea is to make an array of numbers. Starting with 2, cross out all multiples of 2 greater than 2. Next cross out … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , , , , | 4 Comments