back

This is my first cautious approach to C#. I wrote this to get a idea how programming in C# feels like. The program hence makes no use of the object-oriented paradigm and implements a fully static class.
Yet, I wanted my first C# program to be something more interesting than HelloWorld. What came to my mind was a prime number generator:

Domains like shared-key cryptography require the generation of large prime numbers, which is computationally expensive using the naive approach. A more effective way to test, whether a given number n is prime was suggested by  Miller&Rabin as an iterative test that trades completeness for efficiency. Using Fermat's little theorem, the algorithm randomly picks m numbers in the range {1,..,n-1} as potential whitnesses for n not being prime. If no whitness is found, n is assumed to be prime. The higher m, the lower is the chance that n is falsely assumed to be prime (false positive).
The implementation at hand allows the fast generation of all prime numbers within a given range. To lower the risk of false positives, the number of iterations (m) can be passed as a parameter (default=10).

The archive below contains the C# source files and a shell-based .NET executable. For use in your own projects, please refer to the !Readme.txt in the archive.

download prime (6KB)


Note: This program is a .NET based application. You may need the .NET runtime Framework to make it run on older Windows Systems.

You can get the runtime distributable from Microsoft.