Function Miller_Rabin(ByVal n As Integer) As Boolean If n <= 3 Then : Return True ElseIf n Mod 2 = 0 Then : Return False Else Dim k, s, a, d, x As Integer k = 3 d = n - 1 While d Mod 2 = 0 d = d / 2 s += 1 End While For c = 1 To k a = Random(2, n - 1) x = a ^ d Mod n If x = 1 Or x = n - 1 Then GoTo skip For r = 1 To s - 1 x = x ^ 2 Mod n If x = 1 Then Return False Exit Function Else If x = n - 1 Then GoTo skip Else Return False Exit Function End If End If Next skip: Next Return True End If End Function Function Random(ByVal x As Integer, ByVal n As Integer) As Integer Dim a As Integer = Now.Millisecond * Now.Second skip: a = (a ^ 2 + 1) Mod (n + 1) If a < x Then GoTo skip Else Return a End If End Function