Bill Allombert on Tue, 27 Mar 2018 20:29:56 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Random bitstring generation in PARI library


On Tue, Mar 27, 2018 at 02:41:46PM +0300, Aleksandr Lenin wrote:
> Hello,
> 
> what is the procedure to generate a random k-bit number, where k is
> greater than BITS_IN_LONG?

In GP, random(2^k)

> Reading through the manual
> (https://pari.math.u-bordeaux.fr/pub/pari/manuals/2.10.0/libpari.pdf) I
> managed to find only pari_rand, random_bits, random_Fl which return an
> (unsigned) long, and I need a bigger number. The function randomi indeed
> returns a GEN, but in the range 1..p-1, but I need a random bitstring of
> length k.

In C you can do randomi(int2n(k))

Cheers,
Bill.