arb/arf/urandom.c

37 lines
780 B
C
Raw Permalink Normal View History

2021-05-18 01:41:46 +02:00
/*
2021-05-18 22:52:35 +02:00
Copyright (C) 2021 Albin Ahlbäck
2021-05-18 01:41:46 +02:00
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#include "arf.h"
void
arf_urandom(arf_t x, flint_rand_t state, slong bits, arf_rnd_t rnd)
{
slong prec = bits;
fmpz_t n;
fmpz_t t;
prec += 128;
fmpz_init(n);
fmpz_one(n);
fmpz_mul_2exp(n, n, (ulong) prec);
fmpz_init(t);
fmpz_randm(t, state, n);
arf_set_round_fmpz(x, t, bits, rnd);
arf_mul_2exp_si(x, x, -prec);
2021-05-18 22:52:35 +02:00
fmpz_clear(n);
2021-05-18 01:41:46 +02:00
fmpz_clear(t);
}
2021-05-18 22:52:35 +02:00