IsPrime – Determine whether a number is prime
‘ Return True if the number is primeFunction IsPrime(ByVal number As Long) As Boolean ‘ manually test 2 and 3 If number > 3 Then If number Mod 2 =
‘ Return True if the number is primeFunction IsPrime(ByVal number As Long) As Boolean ‘ manually test 2 and 3 If number > 3 Then If number Mod 2 =
‘ number of permutations of N objects in groups of M” Note: requires the FACTORIAL routineFunction Permutations(ByVal Objects As Long, ByVal GroupSize As Long) As Double Permutations = Factorial(Objects) /
‘ The factorial of a number” if NUMBER is negative or >170 it raises an’ “subscript out of range” errorFunction Factorial(ByVal number As Long) As Double Static result(170) As Double
‘ the Greatest Common Divisor of two integers’ (it uses the Euclide’s algorithm)’ if either argument is zero you get a “Division by Zero” errorFunction GCD(ByVal n1 As Long, ByVal
‘ A random number in the range (low, high)Function Rnd2(low As Single, high As Single) As Single Rnd2 = Rnd * (high – low) + lowEnd Function
‘ number of Combinations of N objects in groups of M” Note: requires the FACTORIAL routineFunction Combinations(ByVal Objects As Long, ByVal GroupSize As Long) As Double Combinations = (Factorial(Objects) /
‘ the Least Common Multiple of two integers’ (it uses the Euclide’s algorithm)’ if either argument is zero you get a “Division by Zero” error” Note: if your app also
‘ The fractional part of a floating-point number’ note that negative numbers return negative valuesFunction Fract(number As Variant) As Variant Fract = number – Fix(number)End Function
‘ Base 10 logarithmFunction Log10(number As Double) As Double Log10 = Log(number) / 2.30258509299405End Function