Miller–Rabin primality test: Difference between revisions

added Julia example
(added Julia example)
Line 1,285:
 
for(var i=1;i<=1000;i++) if(isPrime(i)) console.log(i);</lang>
 
=={{header|Julia}}==
The built-in <code>isprime</code> function uses the Miller-Rabin primality test. Here is the implementation of <code>isprime</code> from the Julia standard library (Julia version 0.2):
<lang julia>function isprime(n::Integer)
n == 2 && return true
(n < 2) | iseven(n) && return false
s = trailing_zeros(n-1)
d = (n-1) >>> s
for a in witnesses(n)
a < n || break
x = powermod(a,d,n)
x == 1 && continue
t = s
while x != n-1
(t-=1) <= 0 && return false
x = oftype(n, widemul(x,x) % n)
x == 1 && return false
end
end
return true
end
</lang>
 
=={{header|Liberty BASIC}}==
Anonymous user