- Written by: Jason Ross
Prime numbers appear everywhere in science and nature. They're very handy when it comes to solving puzzles as well, so it having a generator would be useful.
Unfortunately .NET doesn't seem to have a usable prime number generator class, and neither does the C++ Standard Library. It seems that if you want one, you need to write one.
Ruby has some quite nice prime generation facilities built in, and as of version 1.9 they're quite fast (for a scripted language!). It might be worth looking at how the Ruby designers implemented their classes later, and seeing if we can improve on them.
Let's start with the (very) basics. If we want to generate prime numbers, we need a way to check whether a number is prime or not.