how to generate a large prime numbers in vb
using fermat algorithm.

4
Contributors
7
Replies
34
Views
4 Years
Discussion Span
Last Post by tinstaafl

thank you.

if i want to generate the prime number randomly, what will i do ?

looks like we are both grumpy cats :)

how to generate a large prime numbers in vb
using fermat algorithm.

Actually using fermat algorithm, all you get is best guesses, with a high degree of probability of being prime.

Here's a simple little function that will check if a number is prime:

``````Private Function CheckForPrime(ByVal Num As Integer) As Boolean
CheckForPrime = True
If Num <> 2 Then
For i = 3 To Num / 3 Step 2
If Num Mod i = 0 Then
CheckForPrime = False
End If
Next
End If
End Function
``````

oops, gotta stop trying to throw code together when I'm rushed for time :). Couple errors in that code this one should work better:

``````Private Function CheckForPrime(ByVal Num As Integer) As Boolean
CheckForPrime = True
If Num <> 2 Then
If Num Mod 2 = 0 Or Num = 1 Then
CheckForPrime = False
Else
For i = 3 To Num / 3 Step 2
If Num Mod i = 0 Then
CheckForPrime = False
Return CheckForPrime
End If
Next
End If
End If
End Function
``````

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.