randomprime.frink

View or download randomprime.frink in plain text format


// Simple function to generate random prime numbers with a specified
// number of bits.

randomPrime[bits] :=
{
   base = 2^(bits-1) + 1
   while(true)
   {
      b = base + randomBits[bits-2] * 2
      if (isPrime[b])
         return b
      else
         b = b + 2
   }
}

b = eval[input["Enter number of bits: "]]

count = 100
start = now[]
for a = 1 to count
{
   m = randomPrime[b]
   println[m->binary]
}
end = now[]

println["Average generation took " + ((end-start)/count -> ms) + " ms."]


View or download randomprime.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 17591 days, 17 hours, 39 minutes ago.