Class: Sperm::RandomPermutations

Inherits:
Object
  • Object
show all
Defined in:
lib/sperm/random_permutations.rb

Overview

Generates random permutations of given order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, random = Random.new, groups = Groups::GroupsCollection::DEFAULT) ⇒ RandomPermutations

Returns a new instance of RandomPermutations



11
12
13
14
15
16
17
# File 'lib/sperm/random_permutations.rb', line 11

def initialize(order, random = Random.new, groups = Groups::GroupsCollection::DEFAULT)
  isomorphism = groups.find_suitable_isomorphism(order)
  fail NoSuitableGroup, order unless isomorphism
  random_source = RandomSource.new(random)
  @order = order
  @shuffler = Groups::ZpMulShuffler.new(isomorphism, random_source)
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order



9
10
11
# File 'lib/sperm/random_permutations.rb', line 9

def order
  @order
end

Instance Method Details

#randObject



19
20
21
# File 'lib/sperm/random_permutations.rb', line 19

def rand
  @shuffler.rand.select { |element| element.between?(1, order) }.map { |element| element - 1 }
end