thank you.

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

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 3 Years Ago by tinstaafl

This article has been dead for over six months. Start a new discussion instead.