# [seqfan] Re: PARI/GP's random function, A260083

Hugo Pfoertner yae9911 at gmail.com
Sun Sep 18 21:42:48 CEST 2016

```O.k., then it's clear. The 32 bit version of PARI uses the xorgens RNG with
the re-defined data type (instead of long int)

typedef unsigned int UINT; /* Type for random 32 or 64-bit integer,
e.g. unsigned long, unsigned long long,
uint64_t, unsigned int or uint32_t */

and then the program

const int seed0=1;

int main() {
UINT i, x, xp, seed=seed0;
x = xor4096i(seed);
printf("First random number  %llu %lu %llu\n",x, x>>1, seed);
for (i=0; i<20; i++) { x=xor4096i(0); xp = x>>1; printf ("%llu %lu\n",x,
xp); }

produces

linux-qpwl:/home/yae9911/math/random/xorgens # ./a.out
First random number  653022955 326511477 1
2724349216 1362174608
1806534897 903267448
1312695376 656347688
3706911745 1853455872
1387580271 693790135
3487625564 1743812782
2763699378 1381849689
3838768625 1919384312
1122061187 561030593
1221804176 610902088
3460730515 1730365257
2762761179 1381380589
2874667397 1437333698
3760286301 1880143150
3722571052 1861285526
270542510 135271255
4125574268 2062787134
953624032 476812016
1497426196 748713098
1404550014 702275007

where the second column is exactly A260083. What is the period of this RNG?
2^1024?

Do we need a new sequence for the 64 bit case?

Hugo Pfoertner

On Sun, Sep 18, 2016 at 9:27 PM, M. F. Hasler <oeis at hasler.fr> wrote:

> On Sun, Sep 18, 2016 at 2:52 PM, <israel at math.ubc.ca> wrote:
>
> > I get the same numbers as Hugo, on GP/PARI CALCULATOR Version 2.7.4
> > (released).
> >
>
> On version 2.6.1 (alpha), mingw (ix86/GMP-5.0.1 kernel) 32-bit version, gcc
> version 4.6.3
> I get Felix' terms (those listed in A260083 <http://oeis.org/A260083>):
>
> (10:35) gp > random
> %33 = 326511477
>
> Maybe it's rather a question of 32 vs 64 bit, or mingw vs native linux
> and/or gcc version ?
> --
> Maximilian
>
>
> > On Sep 18 2016, Hugo Pfoertner wrote:
> >
> > Seqfans,
> >>
> >> Felix FrÃ¶hlich's http://oeis.org/A260083 claims to be the numbers
> >> produced by PARI's random function when called without argument (i.e.
> using
> >> the default argument 2^31). Nothing is said about initialization, also
> not
> >> in the PARI documentation at http://pari.math.u-bordeaux.fr
> >> /dochtml/html/Conversions_and_similar_elementary_functions_
> >> or_commands.html
> >>
> >> When I try to reproduce the sequence by calling PARI/GP, I get
> >> GP/PARI CALCULATOR Version 2.5.3 (released)
> >>
> >> ? for(n=1,10,print(random))
> >> 1546275796
> >> 879788114
> >> 1745191708
> >> 771966234
> >> 1247963869
> >> 1611845387
> >> 1529973242
> >> 2093650929
> >> 1860635684
> >> 1497261229
> >> ...
> >>
> >> which differs from A260083: 326511477, 1362174608, 903267448, 656347688,
> >> 1853455872, ...
> >>
> >> My results are compliant with the initialization by seed=1 of the
> internal
> >> function given in PARI's current source code in function random.c
> >>
> >> void pari_init_rand(void) { init_xor4096i(1); }
> >>
> >> I get the same result by running Richard Brent's source code from the
> >> http://wwwmaths.anu.edu.au/~brent/ftp/random/xorgens305.tar.gz provided
> >> at
> >> http://maths-people.anu.edu.au/~brent/random.html
> >>
> >> With an initialization by the seed 1, the function UINT xor4096i(UINT
> >> seed)  provided by R. Brent yields the 64-bit number sequence in the
> first
> >> column, and the PARI random numbers by a right shift of 33.
> >>
> >> const int seed0=1;
> >>
> >> int main() {
> >>  UINT i, x, xp, seed=seed0;
> >>  x = xor4096i(seed);
> >>  printf("First random number  %llu %lu %llu\n",x, x>>33, seed);
> >>  for (i=0; i<20; i++) { x=xor4096i(0); xp = x>>33; printf ("%llu
> %lu\n",x,
> >> xp); }
> >>
> >> First random number
> >> 13282407956253574712 1546275796 1
> >> 7557322358563246340 879788114
> >> 14991082624209354397 1745191708
> >> 6631139461101160670 771966234
> >> 10719928016004921607 1247963869
> >> 13845646450878251009 1611845387
> >> 13142370077570254774 1529973242
> >> 17984324540840297179 2093650929
> >> 15982738825684268908 1860635684
> >> 12861376030615125811 1497261229
> >> 9837491998535547791 1145234796
> >> 10009796384580774444 1165293667
> >> 10598342506117936052 1233809453
> >> 6743270311476307786 785019983
> >> 2169871353760194456 252606271
> >> 959683757796537189 111721893
> >> 4063307077606482163 473031201
> >> 8614063320694916486 1002808953
> >> 5278298332222909972 614474799
> >> 4049421542817092888 471414712
> >> 562706585515371056 65507668
> >>
> >> I tried all possible 32-bit seeds, but failed to produce the first term
> of
> >> A260083, 326511477.
> >>
> >> Can someone please try to run a recent version of PARI to check my and
> >> Felix's results?
> >>
> >> Hugo Pfoertner
> >>
> >
>
> --
> Seqfan Mailing list - http://list.seqfan.eu/
>
```