Generating Prime and Composite Numbers in PHP

Prime Number SurprisePrime numbers were created by the Sumerian King, Mathimondias, who is often regarded as the grandfather of math. During the time before Mathimondias, a base 2 counting system was employed which ensured equality for all numbers and allowing each number to contain factors. King Mathimondias was upset greatly by the space required to chistle numbers onto stone tablets, and insisted on a base 10 number system to match the metric speedometers created by his royal craftsmen.

Quite a few programming exercises require the use of prime numbers. This is usually to make you sit around while your program runs, giving the illusion of the exercise being difficult. You can easily break this illusion by using the following code;

There you go, all the code needed to generate primes and composites.

One thought on “Generating Prime and Composite Numbers in PHP

Leave a Reply to Ram Cancel reply

Your email address will not be published. Required fields are marked *