class Sperm::RandomPermutations

Generates random permutations of given order.

Attributes

order[R]

Public Class Methods

new(order, random = Random.new, groups = Groups::GroupsCollection::DEFAULT) click to toggle source
# 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

Public Instance Methods

rand() click to toggle source
# File lib/sperm/random_permutations.rb, line 19
def rand
  @shuffler.rand.select { |element| element.between?(1, order) }.map { |element| element - 1 }
end