Skip to content

Commit 29f0678

Browse files
committed
lib: use InstallMethodWithRandomSource in more places
1 parent 09b01dd commit 29f0678

18 files changed

Lines changed: 187 additions & 107 deletions

hpcgap/lib/ffeconway.gi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,9 +1562,10 @@ end);
15621562
#M Random -- use Rowspace
15631563
##
15641564

1565-
InstallMethod(Random,
1566-
[IsField and IsFFECollection and IsFinite],
1567-
function(f)
1565+
InstallMethodWithRandomSource( Random,
1566+
"for a random source and a large non-prime finite field",
1567+
[IsRandomSource, IsField and IsFFECollection and IsFinite],
1568+
function(rs, f)
15681569
local d, p, v, fam;
15691570
if Size(f) <= MAXSIZE_GF_INTERNAL then
15701571
TryNextMethod();
@@ -1574,7 +1575,7 @@ InstallMethod(Random,
15741575
fi;
15751576
d := DegreeOverPrimeField(f);
15761577
p := Characteristic(f);
1577-
v := Random(RowSpace(GF(p,1),d));
1578+
v := Random(rs, RowSpace(GF(p,1),d));
15781579
fam := FFEFamily(Characteristic(f));
15791580
return Objectify(fam!.ConwayFldEltDefaultType, [v,d,fail]);
15801581
end);

hpcgap/lib/wordrep.gi

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,13 +1283,12 @@ InstallMethod( Position,
12831283
##
12841284
#M Random( <list> ) . . . . . . . . . . for an infinite list of generators
12851285
##
1286-
InstallMethod( Random,
1287-
"for an infinite list of generators",
1288-
true,
1289-
[ IsList and IsInfiniteListOfGeneratorsRep ], 0,
1290-
function( list )
1286+
InstallMethodWithRandomSource( Random,
1287+
"for a random source and an infinite list of generators",
1288+
[ IsRandomSource, IsList and IsInfiniteListOfGeneratorsRep ], 0,
1289+
function( rs, list )
12911290
local pos;
1292-
pos:= Random( Integers );
1291+
pos:= Random( rs, Integers );
12931292
if 0 <= pos then
12941293
return list[ 2 * pos + 1 ];
12951294
else

lib/algfld.gi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,12 +895,13 @@ end);
895895
##
896896
#M Random
897897
##
898-
InstallMethod(Random,"Alg",true,
899-
[IsAlgebraicExtension],0,
900-
function(e)
898+
InstallMethodWithRandomSource( Random,
899+
"for a random source and an algebraic extension",
900+
[IsRandomSource, IsAlgebraicExtension],
901+
function(rs,e)
901902
local fam,l;
902903
fam:=e!.extFam;
903-
l:=List([1..fam!.deg],i->Random(fam!.baseField));
904+
l:=List([1..fam!.deg],i->Random(rs,fam!.baseField));
904905
l:=ImmutableVector(fam!.rchar,l,true);
905906
return AlgExtElm(fam,l);
906907
end);

lib/ffeconway.gi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,9 +1532,10 @@ end);
15321532
#M Random -- use Rowspace
15331533
##
15341534

1535-
InstallMethod(Random,
1536-
[IsField and IsFFECollection and IsFinite],
1537-
function(f)
1535+
InstallMethodWithRandomSource( Random,
1536+
"for a random source and a large non-prime finite field",
1537+
[IsRandomSource, IsField and IsFFECollection and IsFinite],
1538+
function(rs, f)
15381539
local d, p, v, fam;
15391540
if Size(f) <= MAXSIZE_GF_INTERNAL then
15401541
TryNextMethod();
@@ -1544,7 +1545,7 @@ InstallMethod(Random,
15441545
fi;
15451546
d := DegreeOverPrimeField(f);
15461547
p := Characteristic(f);
1547-
v := Random(RowSpace(GF(p,1),d));
1548+
v := Random(rs, RowSpace(GF(p,1),d));
15481549
fam := FFEFamily(Characteristic(f));
15491550
return Objectify(fam!.ConwayFldEltDefaultType, [v,d,fail]);
15501551
end);

lib/fieldfin.gi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ InstallMethod( GeneratorsOfLeftModule,
5252
## primitive root, for efficiency reasons.
5353
## All other cases are handled by the vector space methods.
5454
##
55-
InstallMethod( Random,
55+
InstallMethodWithRandomSource( Random,
5656
"for a random source and a finite prime field",
5757
[ IsRandomSource, IsField and IsPrimeField and IsFinite ],
5858
{ rs, F } -> Random(rs,1,Size(F)) * One( F ) );
5959

60-
InstallMethod( Random,
60+
InstallMethodWithRandomSource( Random,
6161
"for a random source and a finite field with known primitive root",
6262
[ IsRandomSource, IsField and IsFinite and HasPrimitiveRoot ],
6363
function ( rs, F )

lib/grpffmat.gi

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -470,19 +470,15 @@ end);
470470
##
471471
#M Random( <G> ) . . . . . . . . . . . . . . . . . . . . . . for natural GL
472472
##
473-
InstallMethod( Random,
474-
"for natural GL",
475-
true,
476-
[ IsFFEMatrixGroup and IsFinite and IsNaturalGL ],
477-
0,
478-
function(G)
473+
InstallMethodWithRandomSource( Random,
474+
"for a random source and natural GL",
475+
[ IsRandomSource, IsFFEMatrixGroup and IsFinite and IsNaturalGL ],
476+
function(rs, G)
479477
local m;
480-
m := RandomInvertibleMat( DimensionOfMatrixGroup( G ),
478+
m := RandomInvertibleMat( rs, DimensionOfMatrixGroup( G ),
481479
FieldOfMatrixGroup( G ) );
482-
MakeImmutable(m);
483-
ConvertToMatrixRep(m, FieldOfMatrixGroup(G));
484-
return m;
485-
end );
480+
return ImmutableMatrix(FieldOfMatrixGroup(G), m, true);
481+
end);
486482

487483

488484
#############################################################################
@@ -493,20 +489,16 @@ InstallMethod( Random,
493489
## entry in the upper left corner to arbitrary nonzero values in the field
494490
## $F$ form a set of coset representatives of $SL(n,F)$ in $GL(n,F)$.
495491
##
496-
InstallMethod( Random,
497-
"for natural SL",
498-
true,
499-
[ IsFFEMatrixGroup and IsFinite and IsNaturalSL ],
500-
0,
501-
function( G )
492+
InstallMethodWithRandomSource( Random,
493+
"for a random source and natural SL",
494+
[ IsRandomSource, IsFFEMatrixGroup and IsFinite and IsNaturalSL ],
495+
function(rs, G)
502496
local m;
503-
m:= RandomInvertibleMat( DimensionOfMatrixGroup( G ),
497+
m:= RandomInvertibleMat( rs, DimensionOfMatrixGroup( G ),
504498
FieldOfMatrixGroup( G ) );
505499
MultRowVector(m[1], DeterminantMat(m)^-1);
506-
MakeImmutable(m);
507-
ConvertToMatrixRep(m, FieldOfMatrixGroup(G));
508-
return m;
509-
end );
500+
return ImmutableMatrix(FieldOfMatrixGroup(G), m, true);
501+
end);
510502

511503
#############################################################################
512504
##

lib/grpfp.gi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,17 @@ end );
291291
##
292292
#M Random <gp> )
293293
##
294-
InstallMethod( Random,"fp group", [ IsSubgroupFpGroup and IsFinite],0,
295-
function( gp )
294+
InstallMethodWithRandomSource( Random,
295+
"for a random source and an fp group",
296+
[ IsRandomSource, IsSubgroupFpGroup and IsFinite],
297+
function( rs, gp )
296298
local fam,hom;
297299
fam:=ElementsFamily(FamilyObj(gp));
298300
hom:=FPFaithHom(fam);
299301
if hom=fail then
300302
TryNextMethod();
301303
fi;
302-
return PreImagesRepresentative(hom,Random(Image(hom,gp)));
304+
return PreImagesRepresentative(hom,Random(rs, Image(hom,gp)));
303305
end );
304306

305307
#############################################################################

lib/grpfree.gi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ InstallMethod( IsWholeFamily,
297297
##
298298
#T isn't this a generic group method? (without guarantee about distribution)
299299
##
300-
InstallMethod( Random,
301-
"for a free group",
302-
[ IsAssocWordWithInverseCollection and IsGroup ],
303-
function( M )
300+
InstallMethodWithRandomSource( Random,
301+
"for a random source and a free group",
302+
[ IsRandomSource, IsAssocWordWithInverseCollection and IsGroup ],
303+
function( rs, M )
304304
local len, result, gens, i;
305305

306306
# Get a random length for the word.
307-
len:= Random( Integers );
307+
len:= Random( rs, Integers );
308308
if 0 < len then
309309
len:= 2 * len;
310310
elif len < 0 then
@@ -315,9 +315,9 @@ InstallMethod( Random,
315315

316316
# Multiply 'len' random generator powers.
317317
gens:= GeneratorsOfGroup( M );
318-
result:= Random( gens ) ^ Random( Integers );
318+
result:= Random( rs, gens ) ^ Random( rs, Integers );
319319
for i in [ 2 .. len ] do
320-
result:= result * Random( gens ) ^ Random( Integers );
320+
result:= result * Random( rs, gens ) ^ Random( rs, Integers );
321321
od;
322322

323323
# Return the result.

lib/grpnice.gi

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,11 +782,10 @@ SubgroupMethodByNiceMonomorphism( RadicalGroup,
782782
#M Random( <G> )
783783
##
784784
InstallMethod( Random,
785-
"handled by nice monomorphism",
786-
true,
787-
[ IsGroup and IsHandledByNiceMonomorphism ], 0,
788-
G -> PreImagesRepresentative( NiceMonomorphism( G ),
789-
Random( NiceObject( G ) ) ) );
785+
"for a random source and a group handled by nice monomorphism",
786+
[ IsRandomSource, IsGroup and IsHandledByNiceMonomorphism ], 0,
787+
{rs, G} -> PreImagesRepresentative( NiceMonomorphism( G ),
788+
Random( rs, NiceObject( G ) ) ) );
790789

791790

792791
#############################################################################

lib/grppc.gi

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,20 +1283,17 @@ end );
12831283
##
12841284
#M Random( <pcgrp> )
12851285
##
1286-
InstallMethod( Random,
1287-
"pcgs computable groups",
1288-
true,
1289-
[ IsGroup and CanEasilyComputePcgs and IsFinite ],
1290-
0,
1291-
1292-
function(grp)
1286+
InstallMethodWithRandomSource( Random,
1287+
"for a random source and a pcgs computable groups",
1288+
[ IsRandomSource, IsGroup and CanEasilyComputePcgs and IsFinite ],
1289+
function(rs, grp)
12931290
local p;
12941291

12951292
p := Pcgs(grp);
12961293
if Length( p ) = 0 then
12971294
return One( grp );
12981295
else
1299-
return Product( p, x -> x^Random(1,RelativeOrderOfPcElement(p,x)) );
1296+
return Product( p, x -> x^Random(rs, 1, RelativeOrderOfPcElement(p,x)) );
13001297
fi;
13011298
end );
13021299

0 commit comments

Comments
 (0)