## Desi Winda

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

## Desi Winda

thank you.

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

## ddanbe 2,720

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

## tinstaafl 1,060

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.

## tinstaafl 1,060

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
``````

## tinstaafl 1,060

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
``````