1 /*
2 mpfrx_urandom
3
4 creates a random polynomial
5
6 Copyright (C) 2009 Andreas Enge
7
8 This file is part of the MPFRCX Library.
9
10 The MPFRCX Library is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
14
15 The MPFRCX Library is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with the MPFRCX library; see the file COPYING.LESSER. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 MA 02111-1307, USA.
24 */
25
26 #include "mpfrcx-impl.h"
27
mpfrx_urandom(mpfrx_ptr f,int deg,gmp_randstate_t state)28 void mpfrx_urandom (mpfrx_ptr f, int deg, gmp_randstate_t state) {
29
30 if (deg < 0)
31 f->deg = -1;
32 else {
33 int i;
34 f->deg = (int) gmp_urandomm_ui (state, deg + 1);
35 if (f->size < f->deg + 1)
36 mpfrx_realloc (f, f->deg + 1);
37 for (i = f->deg; i >= 0; i--)
38 mpfr_urandomb (f->coeff [i], state);
39 while (!mpfr_cmp_ui (f->coeff [f->deg], 0))
40 mpfr_urandomb (f->coeff [f->deg], state);
41 }
42 }
43