class Sperm::Groups::ZpMulShuffler
Generates random cyclic representations of (Z/pZ \ {0}, *).
Public Class Methods
new(isomorphism, rand_source)
click to toggle source
# File lib/sperm/groups/multiplicative_shuffler.rb, line 5 def initialize(isomorphism, rand_source) @isomorphism, @rand_source = isomorphism, rand_source end
Public Instance Methods
rand()
click to toggle source
# File lib/sperm/groups/multiplicative_shuffler.rb, line 9 def rand first = 1 + @rand_source.rand(mul_group.modulo - 1) mul_group.produce_cycle(first, rand_mul_generator).lazy end
Private Instance Methods
add_group()
click to toggle source
# File lib/sperm/groups/multiplicative_shuffler.rb, line 27 def add_group @isomorphism.add_group end
mul_group()
click to toggle source
# File lib/sperm/groups/multiplicative_shuffler.rb, line 31 def mul_group @isomorphism.mul_group end
rand_add_generator()
click to toggle source
# File lib/sperm/groups/multiplicative_shuffler.rb, line 21 def rand_add_generator gen = @rand_source.rand(add_group.modulo) gen = (gen + 1) % add_group.modulo until add_group.generator?(gen) gen end
rand_mul_generator()
click to toggle source
# File lib/sperm/groups/multiplicative_shuffler.rb, line 16 def rand_mul_generator add_gen = rand_add_generator @isomorphism.map(add_gen) end