  
  [1X6 [33X[0;0YRandom elements[133X[101X
  
  [33X[0;0YIn this chapter we describe some fundamental mechanisms to produce (pseudo-)
  random  elements  that are used later in Chapter [14X7[114X about searching in groups
  and orbits.[133X
  
  
  [1X6.1 [33X[0;0YRandomizing mutable objects[133X[101X
  
  [33X[0;0YFor certain types of mutable objects one can get a [21Xrandom one[121X by calling the
  following operation:[133X
  
  [1X6.1-1 Randomize[101X
  
  [33X[1;0Y[29X[2XRandomize[102X( [3Xob[103X[, [3Xrs[103X] ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10Ynothing[133X
  
  [33X[0;0YThe  mutable  object [3Xob[103X is changed in place. The value afterwards is random.
  The  optional  second  argument  [3Xrs[103X  must  be a random source and the random
  numbers  used  to  randomize  [3Xob[103X are created using the random source [3Xrs[103X (see
  [14X'Reference: Random Sources'[114X). If [3Xrs[103X is not given, then the global [5XGAP[105X random
  number generator is used.[133X
  
  [33X[0;0YCurrently, there are [2XRandomize[102X methods for compressed vectors and compressed
  matrices over finite fields. See also the [5Xcvec[105X package for methods for [10Xcvec[110Xs
  and [10Xcmat[110Xs.[133X
  
  [33X[0;0YFor vectors and one-dimensional subspaces there are two special functions to
  create a list of random objects:[133X
  
  [1X6.1-2 MakeRandomVectors[101X
  
  [33X[1;0Y[29X[2XMakeRandomVectors[102X( [3Xsample[103X, [3Xnumber[103X[, [3Xrs[103X] ) [32X function[133X
  [6XReturns:[106X  [33X[0;10Ya list of random vectors[133X
  
  [33X[0;0Y[3Xsample[103X must be a vector for the mutable copies of which [2XRandomize[102X ([14X6.1-1[114X) is
  applicable  and  [3Xnumber[103X  must  be a positive integer. If given, [3Xrs[103X must be a
  random  source.  This  function creates a list of [3Xnumber[103X random vectors with
  the  same type as [3Xsample[103X using [2XRandomize[102X ([14X6.1-1[114X). For the creation of random
  numbers the random source [3Xrs[103X is used or, if not given, the global [5XGAP[105X random
  number generator.[133X
  
  [1X6.1-3 MakeRandomLines[101X
  
  [33X[1;0Y[29X[2XMakeRandomLines[102X( [3Xsample[103X, [3Xnumber[103X[, [3Xrs[103X] ) [32X function[133X
  [6XReturns:[106X  [33X[0;10Ya list of normalised random vectors[133X
  
  [33X[0;0Y[3Xsample[103X must be a vector for the mutable copies of which [2XRandomize[102X ([14X6.1-1[114X) is
  applicable  and  [3Xnumber[103X  must  be a positive integer. If given, [3Xrs[103X must be a
  random  source.  This  function  creates  a list of [3Xnumber[103X normalised random
  vectors  with  the  same  type as [3Xsample[103X using [2XRandomize[102X ([14X6.1-1[114X). [21XNormalised[121X
  here  means  that  the first non-zero entry in the vector is equal to [22X1[122X. For
  the  creation  of  random  numbers  the  random source [3Xrs[103X is used or, if not
  given, the global [5XGAP[105X random number generator.[133X
  
  
  [1X6.2 [33X[0;0YProduct replacement[133X[101X
  
  [33X[0;0YFor  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
  [21Xproduct  replacer  object[121X  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.[133X
  
  [1X6.2-1 ProductReplacer[101X
  
  [33X[1;0Y[29X[2XProductReplacer[102X( [3Xgens[103X[, [3Xopt[103X] ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10Ya new product replacer object[133X
  
  [33X[0;0Y[3Xgens[103X  must be a list of group generators. If given, [3Xopt[103X is a [5XGAP[105X record with
  options.  The  operation  creates  a  new  product replacer object producing
  pseudo random elements in the group generated by the generators [3Xgens[103X.[133X
  
  [33X[0;0YThe  exact  algorithm  used  is explained below after the description of the
  options.[133X
  
  [33X[0;0YThe following components in the options record have a defined meaning:[133X
  
  [8X[10Xrandomsource[110X[8X[108X
        [33X[0;6YA  random  source  object  that is used to generate the random numbers
        used.  If  none is specified the global [5XGAP[105X random number generator is
        used.[133X
  
  [8X[10Xscramble[110X[8X[108X
        [33X[0;6YThe  [10Xscramble[110X  value in the algorithm described below can be set using
        this option. The default value is [22X30[122X.[133X
  
  [8X[10Xscramblefactor[110X[8X[108X
        [33X[0;6YThe  [10Xscramblefactor[110X  value in the algorithm described below can be set
        using this option. The default value is [22X4[122X.[133X
  
  [8X[10Xaddslots[110X[8X[108X
        [33X[0;6YThe  [10Xaddslots[110X  value in the algorithm described below can be set using
        this option. The default value is [22X5[122X.[133X
  
  [8X[10Xmaxdepth[110X[8X[108X
        [33X[0;6YIf  [10Xmaxdepth[110X  is  set,  then  the production of pseudo random elements
        starts  all  over  whenever  [10Xmaxdepth[110X  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
        [10Xmaxdepth[110X to [22X300[122X or [22X400[122X.[133X
  
  [8X[10Xnoaccu[110X[8X[108X
        [33X[0;6YWithout  this  option  set  to  [9Xtrue[109X  the  [21Xrattle[121X  version  of product
        replacement  is  used  which  involves  an accumulator and uses two or
        three  products per random element. To use the [21Xshake[121X version with only
        one  or  two product replacement per random element set this component
        to  [9Xtrue[109X.  The exact number of multiplications per random element also
        depends on the value of the [10Xaccelerator[110X component.[133X
  
  [8X[10Xnormalin[110X[8X[108X
        [33X[0;6YThere  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
        [10Xnormalin[110X component to a product replacer object working in the ambient
        group.  In  every  step  two elements [22Xa[122X and [22Xb[122X are picked and then [22Xa[122X is
        either replaced by [22Xa*b^c[122X or [22Xb^c*a[122X (with equal probability), where [22Xc[122X is
        a  random  element  from  the  ambient  group  produced by the product
        replacer  in  the  [10Xnormalin[110X component. It is recommended to switch off
        the accumulator and accelerator in the product replacer object for the
        ambient  group.  Then  to  produce  one  random  element in the normal
        closure needs four multiplications.[133X
  
  [8X[10Xaccelerator[110X[8X[108X
        [33X[0;6YIf  this  option  is  set  to  [9Xtrue[109X  (which  is the default), then the
        accelerator  is  used.  This  means  that  in  each  step  two product
        replacement  steps are performed, where both involve one distinguished
        slot  called  the [21Xcaptain[121X. The idea is that the current [21Xteam[121X of random
        elements  uses  one  amongst them more often to increase the length of
        the  words  produced.  See below for details of the algorithm with and
        without accelerator.[133X
  
  [8X[10Xretirecaptain[110X[8X[108X
        [33X[0;6YIf  this  component  is  bound  to a positive integer then the captain
        retires  after so many steps of the algorithm. This is to use only two
        multiplications  for  each random element in the long run after proper
        mixing.  The  default  value for [10Xretirecaptain[110X is twice the scrambling
        time.[133X
  
  [8X[10Xaccus[110X[8X[108X
        [33X[0;6YThis  component (default is 5) is the number of accumulators to use in
        the  rattle  variant. All accus are used in a round robin fashion. The
        purpose   of   multiple  accus  is  to  have  a  greater  stochastical
        independence of adjacent random elements in the sequence.[133X
  
  [33X[0;0YThe  algorithm  used  does  the  following:  A list of [10XLength([110X[3Xgens[103X[10X)+addslots[110X
  elements is created that starts with the elements [3Xgens[103X and is filled up with
  random  generators  from  [3Xgens[103X.  This  element is called the [21Xteam[121X. A product
  replacement  without  accelerator  randomly chooses two elements in the list
  and  replaces  one  of  them by the product of the two. If an accelerator is
  used,  then  one product replacement step randomly chooses two slots [22Xi[122X and [22Xj[122X
  where  [22Xi,j > 1[122X but [22Xi=j[122X is possible. Then first [22Xl[1][122X is replaced by [22Xl[1]*l[i][122X
  and  after  that  [22Xl[j][122X  is  replaced  by [22Xl[j]*l[1][122X. The first team member is
  called the [21Xcaptain[121X, so the captain is involved in every product replacement.[133X
  
  [33X[0;0YOne  step  in  the  algorithm  is  to do one product replacement followed by
  post-multiplying  the  result  to  the accumulator if one (or more) is used.
  Multiple accus (see the [10Xaccus[110X component) are used in a round robin fashion.[133X
  
  [33X[0;0YFirst  [10XMaximum(Length([110X[3Xgens[103X[10X)*scramblefactor,scramble)[110X  steps  are  performed.
  After  this  initialisation  for  every random element requested one step is
  done and the resulting element returned.[133X
  
  [1X6.2-2 Next[101X
  
  [33X[1;0Y[29X[2XNext[102X( [3Xpr[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10Ya (pseudo-) random group element g[133X
  
  [33X[0;0Y[3Xpr[103X  must  be  a  product  replacer  object.  This operation makes the object
  generate the next random element and return it.[133X
  
  [1X6.2-3 Reset[101X
  
  [33X[1;0Y[29X[2XReset[102X( [3Xpr[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10Ynothing[133X
  
  [33X[0;0Y[3Xpr[103X  must  be  a product replacer object. This operation resets the object in
  the  sense  that  it resets the product replacement back to the state it had
  after  scrambling.  Note  that  since  the  random  source is not reset, the
  product replacer object will return another sequence of random elements than
  before.[133X
  
  [1X6.2-4 AddGeneratorToProductReplacer[101X
  
  [33X[1;0Y[29X[2XAddGeneratorToProductReplacer[102X( [3Xpr[103X, [3Xel[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10Ynothing[133X
  
  [33X[0;0Y[3Xpr[103X  must be a product replacer object. This operation adds the new generator
  [3Xel[103X  to  the product replacer without needing a completely new initialisation
  phase.  From  after  this  call on the product replacer will generate random
  elements  in  the  group generated by the old generators and the new element
  [3Xel[103X.[133X
  
