Do you need to use Random numbers? Can't you just pick a set of integers -
either those from t2, sage.math, or the lottery numbers, and use them instead?
Dave
My guess is that it is due to the endianness of the machine. For
example, check out this snippet from sage.misc.randstate:
# 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.
If you're using GAP from withing Sage, you might just want to do
current_randstate().set_seed_gap() to initialize the random number
generators. Note that both of the following are reset:
prev_mersenne_seed = gap.Reset(gap.GlobalMersenneTwister,
mersenne_seed)
prev_classic_seed = gap.Reset(gap.GlobalRandomSource, classic_seed)
--Mike
Yes. x86 are little endian. SPARC is big endian.
I can try the code if you want on my OpenSolaris system. That uses an Intel Xeon
processor, so is little endian.
I used to work on a 24-bit machine. Either the most (or least), my memory fails
me, was in the middle!
I would be very weary of any random number generator that claims to be a good
source of random numbers if the output differs by platform or compilation mode.
Someone would need to check the numbers for randomless on these different systems.
There are a number of statistical tests for pseudo random number generators -
but I expect you know that anyway.
> Cheers,
> Simon
>
Dave
This is on a Sun Ultra 27 running OpenSolaris, with a Xeon box.
sage -t -long devel/sage/sage/quadratic_forms/quadratic_form__siegel_product.py
[164.1 s]
----------------------------------------------------------------------
All tests passed!
Total time for all tests: 1825.6 seconds
drkirkby@hawk:~/noatlas/sage-4.5.3.rc0$ ./sage -gap
######### ###### ########### ###
############# ###### ############ ####
############## ######## ############# #####
############### ######## ##### ###### #####
###### # ######### ##### ##### ######
###### ########## ##### ##### #######
##### ##### #### ##### ###### ########
#### ##### ##### ############# ### ####
##### ####### #### #### ########### #### ####
##### ####### ##### ##### ###### #### ####
##### ####### ##### ##### ##### #############
##### ##### ################ ##### #############
###### ##### ################ ##### #############
################ ################## ##### ####
############### ##### ##### ##### ####
############# ##### ##### ##### ####
######### ##### ##### ##### ####
Information at: http://www.gap-system.org
Try '?help' for help. See also '?copyright' and '?authors'
Loading the library. Please be patient, this may take a while.
GAP4, Version: 4.4.12 of 17-Dec-2008, i386-pc-solaris2.11-gcc
gap> Reset(GlobalMersenneTwister);; List([1..10],i->Random(1,100000));
[ 85758, 234, 18408, 12676, 2507, 38166, 24692, 15013, 4755, 94043 ]
gap>
This is what I said in my first response and can be taken care of with
current_randstate().set_seed_gap().
Core2:
sage: set_random_seed(100)
sage: current_randstate().set_seed_gap()
sage: gap.eval('List([1..10],i->Random(1,100000));')
'[ 80761, 80557, 8462, 25730, 32000, 92371, 85402, 52347, 17181, 2889 ]'
t2:
sage: set_random_seed(100)
sage: current_randstate().set_seed_gap()
sage: gap.eval('List([1..10],i->Random(1,100000));')
'[ 80761, 80557, 8462, 25730, 32000, 92371, 85402, 52347, 17181, 2889 ]'
--Mike
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
It depends what you mean by "differs". For "real" random numbers, you
can only discuss different statistical properties of the sequences
because the actual sequencee of numbers cannot be predicted or repeated.
For pseudo-random sequences, you can additionally talk about the
actual sequence of numbers returned by the rng. The documentation for
most rng's talks about sequences being repeatable by calling an
initialisation function with the same seed but generally does not
state the scope of the repeatability - so actual sequences generated
by a specific seed could potentially vary on different platforms.
I would suggest that the bigger problem is that the GAP doctest relies
on a specific sequence of random numbers being used by GAP but does
not control or test the actual sequence of random numbers.
--
Peter Jeremy
Yep.
--Mike