Use Prime to generate prime numbers : Prime Numbers « Number « Ruby






Use Prime to generate prime numbers



#!/usr/bin/env ruby

require 'mathn'

prime_number = Prime.new # instantiate a Prime object
prime_number.next # => 2 # return the next prime number (seed = 1)
prime_number.succ # => succ works, too

# print the next prime number as a string
puts "The next prime number is " + prime_number.next.to_s + "."
# => The next prime number is 5.

 








Related examples in the same category

1.Prime Numbers
2.Generates 25 prime numbers from 2 to 97
3.Use each method from Prime class
4.Generating Prime Numbers with succ
5.Pass code block into each