Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RandomSource in a few more places #1599

Merged
merged 8 commits into from
Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions hpcgap/lib/random.g
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ end);
R_228 := 2^28;
RANDOM_LIST := function ( list )
local r_n, r_x;
r_n := VAL_GVAR(_R_N);
r_n := VAL_GVAR(_R_N) mod 55 + 1;
r_x := VAL_GVAR(_R_X);
ASS_GVAR(_R_N, r_n mod 55 + 1);
ASS_GVAR(_R_N, r_n);
r_x[r_n] := (r_x[r_n] + r_x[(r_n+30) mod 55+1]) mod R_228;
return list[ QUO_INT( r_x[r_n] * LEN_LIST(list), R_228 ) + 1 ];
end;
Expand All @@ -49,9 +49,10 @@ RANDOM_SEED := function ( n )
r_x[i] := (1664525 * r_x[i-1] + 1) mod R_228;
od;
for i in [1..99] do
ASS_GVAR(_R_N, r_n mod 55 + 1);
r_n := r_n mod 55 + 1;
r_x[r_n] := (r_x[r_n] + r_x[(r_n+30) mod 55+1]) mod R_228;
od;
ASS_GVAR(_R_N, r_n);
end;

BIND_GLOBAL("RANDOM_SEED_CONSTRUCTOR", function()
Expand Down
244 changes: 0 additions & 244 deletions hpcgap/lib/random.gi

This file was deleted.

10 changes: 5 additions & 5 deletions hpcgap/lib/zmodnz.gi
Original file line number Diff line number Diff line change
Expand Up @@ -772,12 +772,12 @@ InstallMethod( AsSSortedList,
##
#M Random( <R> ) . . . . . . . . . . . . . . . . . method for full ring Z/nZ
##
InstallMethod( Random,
"for full ring Z/nZ",
[ IsZmodnZObjNonprimeCollection and IsWholeFamily ],
InstallMethodWithRandomSource(Random,
"for a random source and full ring Z/nZ",
[ IsRandomSource, IsZmodnZObjNonprimeCollection and IsWholeFamily ],
RankFilter( IsRing ),
R -> ZmodnZObj( ElementsFamily( FamilyObj( R ) ),
Random( [ 0 .. Size( R ) - 1 ] ) ) );
{ rs, R } -> ZmodnZObj( ElementsFamily( FamilyObj( R ) ),
Random( rs, [ 0 .. Size( R ) - 1 ] ) ) );


#############################################################################
Expand Down
14 changes: 7 additions & 7 deletions lib/fieldfin.gi
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ InstallMethod( GeneratorsOfLeftModule,
## All other cases are handled by the vector space methods.
##
InstallMethod( Random,
"for a finite prime field",
[ IsField and IsPrimeField and IsFinite ],
F -> Random(1,Size(F)) * One( F ) );
"for a random source and a finite prime field",
[ IsRandomSource, IsField and IsPrimeField and IsFinite ],
{ rs, F } -> Random(rs,1,Size(F)) * One( F ) );

InstallMethod( Random,
"for a finite field with known primitive root",
[ IsField and IsFinite and HasPrimitiveRoot ],
function ( F )
"for a random source and a finite field with known primitive root",
[ IsRandomSource, IsField and IsFinite and HasPrimitiveRoot ],
function ( rs, F )
local rnd;
rnd := Random( 0, Size( F )-1 );
rnd := Random( rs, 0, Size( F )-1 );
if rnd = 0 then
rnd := Zero( F );
else
Expand Down
15 changes: 9 additions & 6 deletions lib/matrix.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1615,16 +1615,17 @@ DeclareGlobalFunction( "ReflectionMat" );

#############################################################################
##
#F RandomInvertibleMat( <m> [, <R>] ) . . . make a random invertible matrix
#F RandomInvertibleMat( [rs ,] <m> [, <R>] ) . . . random invertible matrix
##
## <#GAPDoc Label="RandomInvertibleMat">
## <ManSection>
## <Func Name="RandomInvertibleMat" Arg='m [, R]'/>
## <Func Name="RandomInvertibleMat" Arg='[rs ,] m [, R]'/>
##
## <Description>
## <Ref Func="RandomInvertibleMat"/> returns a new mutable invertible random
## matrix with <A>m</A> rows and columns with elements taken from the ring
## <A>R</A>, which defaults to <Ref Var="Integers"/>.
## Optionally, a random source <A>rs</A> can be supplied.
## <Example><![CDATA[
## gap> m := RandomInvertibleMat(4);
## [ [ -4, 1, 0, -1 ], [ -1, -1, 1, -1 ], [ 1, -2, -1, -2 ],
Expand All @@ -1642,16 +1643,17 @@ DeclareGlobalFunction( "RandomInvertibleMat" );

#############################################################################
##
#F RandomMat( <m>, <n> [, <R>] ) . . . . . . . . . . . make a random matrix
#F RandomMat( [rs ,] <m>, <n> [, <R>] ) . . . . . . . . make a random matrix
##
## <#GAPDoc Label="RandomMat">
## <ManSection>
## <Func Name="RandomMat" Arg='m, n [, R]'/>
## <Func Name="RandomMat" Arg='[rs ,] m, n [, R]'/>
##
## <Description>
## <Ref Func="RandomMat"/> returns a new mutable random matrix with <A>m</A> rows and
## <A>n</A> columns with elements taken from the ring <A>R</A>, which defaults
## to <Ref Var="Integers"/>.
## Optionally, a random source <A>rs</A> can be supplied.
## <Example><![CDATA[
## gap> RandomMat(2,3,GF(3));
## [ [ Z(3), Z(3), 0*Z(3) ], [ Z(3), Z(3)^0, Z(3) ] ]
Expand All @@ -1665,15 +1667,16 @@ DeclareGlobalFunction( "RandomMat" );

#############################################################################
##
#F RandomUnimodularMat( <m> ) . . . . . . . . . . random unimodular matrix
#F RandomUnimodularMat( [rs ,] <m> ) . . . . . . . . random unimodular matrix
##
## <#GAPDoc Label="RandomUnimodularMat">
## <ManSection>
## <Func Name="RandomUnimodularMat" Arg='m'/>
## <Func Name="RandomUnimodularMat" Arg='[rs ,] m'/>
##
## <Description>
## returns a new random mutable <A>m</A><M>\times</M><A>m</A> matrix with integer
## entries that is invertible over the integers.
## Optionally, a random source <A>rs</A> can be supplied.
## <Example><![CDATA[
## gap> m := RandomUnimodularMat(3);
## [ [ -5, 1, 0 ], [ 12, -2, -1 ], [ -14, 3, 0 ] ]
Expand Down
Loading