On Mon, Sep 6, 2010 at 9:31 PM, Dima Pasechnik <dimp...@gmail.com> wrote:
> I wonder how does GAP pick up the seed? (Don't even know where to look
> in the code...)

It is in sage/misc/randstate.pyx.

> On the other hand, how would one call
> current_randstate().set_seed_gap()  from GAP?

You can't call it from GAP, but it just does the following calls

             prev_mersenne_seed = gap.Reset(gap.GlobalMersenneTwister,
mersenne_seed)
             prev_classic_seed = gap.Reset(gap.GlobalRandomSource, classic_seed)

which are just GAP calls.  If the machine is little endian, then
classic_seed and mersenne_seed are the same.  If the machine is big
endian, then the following following comment applies:

                     # GAP's random number generator initialization
                     # (in integer.c, in FuncInitRandomMT) takes its
                     # seed as a string, then converts this string into
                     # an array of 32-bit integers just by casting the
                     # pointer.  Thus, the result depends on the
                     # endianness of the machine.  As a workaround, we
                     # swap the bytes in the string ourselves, so that
                     # GAP always gets the same array of integers.

Thus, the following is done

                     seed = str(seed)
                     new_seed = ''
                     while len(seed) >= 4:
                         new_seed += seed[3::-1]
                         seed = seed[4:]
                     seed = '"' + new_seed + '"'
                     mersenne_seed = seed

--Mike

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to