Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime Number Generator
#9
This is about as simple as it gets:

A sieve generator:

Code: (Select All)
Print "Enter array size";: Input m
d = m ^ 2
ReDim p(d) As _Byte
For x = 2 To m
  For l = x + x To d Step x
      If l <= d Then
        p(l) = -1
      End If
  Next
Next
For x = 2 To d
  If p(x) = 0 Then Print x;
Next
End
A brute force generator:

Code: (Select All)
Print "Enter upper range";: Input d
For l = 2 To d
  f = 0
  For m = 2 To Int(Sqr(l))
      If l Mod m = 0 Then f = -1: Exit For
  Next
  If f = 0 Then Print l;
Next
End
Reply


Messages In This Thread
Prime Number Generator - by SierraKen - Yesterday, 06:44 AM
RE: Prime Number Generator - by eoredson - Yesterday, 08:03 AM
RE: Prime Number Generator - by bplus - Yesterday, 03:25 PM
RE: Prime Number Generator - by hsiangch_ong - Yesterday, 04:23 PM
RE: Prime Number Generator - by SierraKen - Yesterday, 05:14 PM
RE: Prime Number Generator - by bplus - Yesterday, 05:21 PM
RE: Prime Number Generator - by bplus - Yesterday, 05:15 PM
RE: Prime Number Generator - by SierraKen - Yesterday, 08:16 PM
RE: Prime Number Generator - by eoredson - Today, 01:52 AM



Users browsing this thread: 5 Guest(s)