End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Integer#miller_rabin_bases
miller_rabin_bases
lib/prime.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/prime.rb, line 69
def miller_rabin_bases
# Miller-Rabin's complexity is O(k log^3n).
# So we can reduce the complexity by reducing the number of bases tested.
# Using values from https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
i = case
when self < 0xffff then
# For small integers, Miller Rabin can be slower
# There is no mathematical significance to 0xffff
return nil
# when self < 2_047 then 0
when self < 1_373_653 then 1
when self < 9_080_191 then 2
when self < 25_326_001 then 3
when self < 3_215_031_751 then 4
when self < 4_759_123_141 then 5
when self < 1_122_004_669_633 then 6
when self < 2_152_302_898_747 then 7
when self < 3_474_749_660_383 then 8
when self < 341_550_071_728_321 then 9
when self < 3_825_123_056_546_413_051 then 10
when self < 318_665_857_834_031_151_167_461 then 11
when self < 3_317_044_064_679_887_385_961_981 then 12
else return nil
end
MILLER_RABIN_BASES[i]
end
No documentation available