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

Recommended Answers

All 7 Replies

thank you.

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

commented: looks like we are both grumpy cats :) +7

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.