[GAP Forum] Random Matrix

Stefan Kohl kohl at mathematik.uni-stuttgart.de
Fri Nov 10 17:12:15 GMT 2006


Dear Forum,

Bruce Colletti wrote:

> In GAP 4.4.9, I want to create a random matrix of arbitrarily large integers.
 > However, I must be able to reset the random number stream so that the same matrices
 > can be regenerated.
> 
> How is this done using RandomMat?

There are two things:

- Random sources can be initialized by the operation `Reset'.
   For the documentation of random sources, see ?Random sources.

   E.g.:

   gap> Reset(GlobalMersenneTwister);;
   gap> RandomMat(2,3,Integers);
   [ [ -1, -4, -1 ], [ -3, -2, 1 ] ]
   gap> Reset(GlobalMersenneTwister);;
   gap> RandomMat(2,3,Integers);
   [ [ -1, -4, -1 ], [ -3, -2, 1 ] ]

- `RandomMat' does not produce matrices with arbitrarily large entries.
   However you can just write your own little function, e.g.:

   RandomLargeIntegerMat := function ( n, m, bound )
     return List([1..n],i->List([1..m],j->Random(-bound,bound)));
   end;

   Then the rest is straightforward:

   gap> Reset(GlobalMersenneTwister);;
   gap> RandomLargeIntegerMat(2,3,10^20);
   [ [ 35478973841434169085, -5727827082917039741, 30043532000967004818 ],
     [ 98456515568185409751, -23365773455484833982, 29964620678188938398 ] ]
   gap> Reset(GlobalMersenneTwister);;
   gap> RandomLargeIntegerMat(2,3,10^20);
   [ [ 35478973841434169085, -5727827082917039741, 30043532000967004818 ],
     [ 98456515568185409751, -23365773455484833982, 29964620678188938398 ] ]

Hope this helps,

     Stefan Kohl

-------------------------------------------------------------------------------
http://www.cip.mathematik.uni-stuttgart.de/~kohlsn/
-------------------------------------------------------------------------------






More information about the Forum mailing list