in reply to Prime Iterator

You might find some analysis and implementations of the AKS algorithm useful.