Class: Prime::Generator23

### Home Classes Methods

### In Files

- lib/backports/1.9.1/stdlib/prime.rb

### Parent

Prime::PseudoPrimeGenerator

### Methods

- ::new
- #next
- #rewind
- #succ

### Class/Module Index

Quicksearch

- Prime
- Prime::EratosthenesGenerator
- Prime::EratosthenesSieve
- Prime::Generator23
- Prime::OldCompatibility
- Prime::PseudoPrimeGenerator
- Prime::TrialDivision
- Prime::TrialDivisionGenerator
- Backports
- Backports::MOST_EXTREME_OBJECT_EVER
- Backports::StdLib
- Backports::StdLib::LoadedFeatures
- Enumerator
- Enumerator::GeneratorBP
- Enumerator::Lazy
- Enumerator::Yielder
- Matrix
- Matrix::EigenvalueDecomposition
- Matrix::LUPDecomposition
- Random
- Random::Implementation
- Random::MT19937
- Enumerable
- Enumerable::Enumerator
- File
- File::Constants
- ARGF
- Array
- BasicObject
- Binding
- Complex
- Dir
- ENV
- Fixnum
- Float
- GC
- Hash
- IO
- Integer
- Kernel
- Math
- Method
- Module
- NilClass
- Numeric
- Object
- ObjectSpace
- OpenStruct
- Proc
- Process
- Range
- Regexp
- Set
- StopIteration
- String
- Struct
- Symbol
- UnboundMethod

No matching classes.

# Prime::Generator23

Generates all integer which are greater than 2 and are not divided by 2 nor 3.

This is a pseudo-prime generator, suitable on checking primality of a integer by brute force method.

### Public Class Methods

new() click to toggle source

    # File lib/backports/1.9.1/stdlib/prime.rb, line 330
    def initialize
      @prime = 1
      @step = nil
      super
    end

### Public Instance Methods

next() click to toggle source
Alias for: succ
rewind() click to toggle source

    # File lib/backports/1.9.1/stdlib/prime.rb, line 352
    def rewind
      initialize
    end

succ() click to toggle source

    # File lib/backports/1.9.1/stdlib/prime.rb, line 336
    def succ
      loop do
        if (@step)
          @prime += @step
          @step = 6 - @step
        else
          case @prime
          when 1; @prime = 2
          when 2; @prime = 3
          when 3; @prime = 5; @step = 2
          end
        end
        return @prime
      end
    end

Also aliased as: next

[Validate]

Generated with the Darkfish Rdoc Generator 2.