Random elements

In this chapter we describe some fundamental mechanisms to produce (pseudo-) random elements that are used later in Chapter about searching in groups and orbits.

Randomizing mutable objects

For certain types of mutable objects one can get a random one by calling the following operation:

nothing
The mutable object ob is changed in place. The value afterwards is random. The optional second argument rs must be a random source and the random numbers used to randomize ob are created using the random source rs (see ). If rs is not given, then the global &GAP; random number generator is used.

Currently, there are methods for compressed vectors and compressed matrices over finite fields. See also the `cvec` package for methods for cvecs and cmats.

For vectors and one-dimensional subspaces there are two special functions to create a list of random objects:

a list of random vectors
sample must be a vector for the mutable copies of which is applicable and number must be a positive integer. If given, rs must be a random source. This function creates a list of number random vectors with the same type as sample using . For the creation of random numbers the random source rs is used or, if not given, the global &GAP; random number generator.
a list of normalised random vectors
sample must be a vector for the mutable copies of which is applicable and number must be a positive integer. If given, rs must be a random source. This function creates a list of number normalised random vectors with the same type as sample using . Normalised here means that the first non-zero entry in the vector is equal to 1. For the creation of random numbers the random source rs is used or, if not given, the global &GAP; random number generator.
Product replacement

For computations in finite groups product replacement algorithms are a viable method of generating pseudo-random elements. This section describes a framework and an object type to provide these algorithms. Roughly speaking a product replacer object is something that is created with a list of group generators and produces a sequence of pseudo random group elements using some random source for random numbers.

a new product replacer object
gens must be a list of group generators. If given, opt is a &GAP; record with options. The operation creates a new product replacer object producing pseudo random elements in the group generated by the generators gens.

The exact algorithm used is explained below after the description of the options.

The following components in the options record have a defined meaning: randomsource A random source object that is used to generate the random numbers used. If none is specified the global &GAP; random number generator is used. scramble The scramble value in the algorithm described below can be set using this option. The default value is 100. scramblefactor The scramblefactor value in the algorithm described below can be set using this option. The default value is 10. addslots The addslots value in the algorithm described below can be set using this option. The default value is 10. maxdepth If maxdepth is set, then the production of pseudo random elements starts all over whenever maxdepth product replacements have been performed. The rationale behind this is that the elements created should be evenly distributed but that the expressions in the generators should not be too long. A good compromise is usually to set maxdepth to 200 or 300. noaccu Without this option set to true the rattle version of product replacement is used which involves an accumulator and uses two products per random element. To use the shake version with only one product replacement per random element set this component to true. normalin There is a variant of the product replacement algorithm that produces elements in the normal closure of the group generated by a list of elements. It needs random elements in the ambient group in which the normal closure is defined. This is implemented here by setting the normalin component to a product replacer object working in the ambient group. It is recommended to switch off the accumulator in the product replacer object for the ambient group. Then to produce one random element in the normal closure needs three multiplications.

The algorithm used does the following: A list of Length(gens)+addslots elements is created that starts with the elements gens and is filled up with random generators from gens. A product replacement randomly chooses two elements in the list and replaces one of them by the product of the two. One step in the algorithm is to do one product replacement followed by post-multiplying the result to the accumulator if one is used. First Maximum(Length(gens)*scramblefactor,scramble) steps are performed. After this initialisation for every random element requested one step is done done and the resulting element returned.
a (pseudo-) random group element g
pr must be a product replacer object. This operation makes the object generate the next random element and return it.
nothing
pr must be a product replacer object. This operation resets the object in the sense that it resets its random source (see ) and reinitialises the random element generation as described above.