Sha256: 42488bbb9e6feddfc4f75fc26ce31fde4c7ad1d7d2a59dffc2909b42c428c3a6
Contents?: true
Size: 682 Bytes
Versions: 1
Compression:
Stored size: 682 Bytes
Contents
require 'sperm/groups' require 'sperm/exceptions' require 'sperm/random_source' module Sperm # Generates random permutations of given order. # class RandomPermutations attr_reader :order 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 def rand @shuffler.rand.select { |element| element.between?(1, order) }.map { |element| element - 1 } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sperm-0.1.1 | lib/sperm/random_permutations.rb |