how to generate a large prime numbers in vb
using fermat algorithm.
Ever thought about google or showing effort at least?
Here is a solution: http://www.freevbcode.com/ShowCode.asp?ID=9430
thank you.
if i want to generate the prime number randomly, what will i do ?
This may also help: http://number.subwiki.org/wiki/Fermat_primality_test
@ddanbe, looks like your also a grumpy cat, my grumpy cat avatar is not satisfied (;D)? (looking at your profile pic compared to mine)
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