GetPrimeNumbers – Evaluate the first N prime numbers

GetPrimeNumbers – Evaluate the first N prime numbers

' Returns an array with the first N prime numbers'' Note: you can easily convert this routine to VB4 and VB5 by' returning the result array through an argument instead of' the return valueFunction GetPrimeNumbers(numberOfPrimes As Long) As Long()    Dim found As Long    Dim n As Long    Dim i As Long        If numberOfPrimes <= 0 Then Err.Raise 1002, , "Invalid argument"        ' we know the size of the result in advance    ReDim result(1 To numberOfPrimes) As Long        ' "2" is the first prime number    result(1) = 2: found = 1        n = 1    Do        ' all other prime numbers are odd, so we can skip even numbers        n = n + 2        ' let's check if N is a prime number        For i = 1 To found            If (n Mod result(i)) = 0 Then Exit For        Next        If i > found Then            ' no prime number < N is a divisor for N            ' therefore N is prime            found = found + 1            result(found) = n            If found = numberOfPrimes Then Exit Do        End If    Loop        GetPrimeNumbers = resultEnd Function

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes