# Looking for Prime Numbers?

## Recommended Posts

Pretty useless, but fun script for calculate prime numbers until a you limit you want.

`;Better code below.`
Edited by ezzetabi
##### Share on other sites

I think that would be useful for my little brother. Let me copy + paste that really quick =)

##### Share on other sites

Just wondering: Should the line If \$primi[\$c] > \$n / 2 Then ExitLoop be

If \$primi[\$c] > Sqrt(\$n) Then ExitLoop

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
##### Share on other sites

Thanks to a CyberSlug idea and a my idea we have a much faster version!

```Dim \$PRIMI[2], \$N = 1, \$C, \$T = 0, \$L, \$LIMIT, \$PATH
\$LIMIT = 5000
\$PATH = 'c:\primi.txt'

If \$LIMIT < 2 Then Exit
\$PRIMI[0] = 1
\$PRIMI[1] = 2
\$FILE = FileOpen(\$PATH, 2)
If \$FILE = -1 Then Exit

FileWrite(\$FILE, '2' & @CRLF);It adds 2 to the file since it is already in the array as begin of all.
HotKeySet('!x', '_Terminate')

While 1
\$N = \$N + 2;It skips all divisible by 2 numbers. The 2 is already added as begin.
;since they can't be prime.
\$T = 0
If \$N >= \$LIMIT Then Exit
For \$C = 1 To \$PRIMI[0]
If \$PRIMI[\$C] > Sqrt(\$N) Then ExitLoop;It avoids useless controls
If Mod(\$N, \$PRIMI[\$C]) = 0 Then
\$T = 1
ExitLoop
EndIf
Next

If \$T = 0 Then
\$L = UBound(\$PRIMI)
ReDim \$PRIMI[\$L + 1]
\$PRIMI[0] = \$L
\$PRIMI[\$L] = \$N
FileWrite(\$FILE, \$PRIMI[\$PRIMI[0]] & @CRLF)
ToolTip(\$PRIMI[\$PRIMI[0]])
EndIf
Wend

Exit
Func _Terminate()
FileClose(\$FILE)
Exit
EndFunc  ;==>_Terminate```
##### Share on other sites

If you really are looking for prime numbers, You can use Prime95 from here: http://www.mersenne.org/freesoft.htm

That is, unless the novelty of this script is not the fact that it finds prime numbers, but that it finds those numbers using autoit.

Who else would I be?
##### Share on other sites

I never said I made somthing new. Also for serious password cracking the limit of Autoit variables is too strict. I made this just for fun.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...