tizen 2.3 release
[external/gmp.git] / rand.c
1 /* gmp_randinit (state, algorithm, ...) -- Initialize a random state.
2
3 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4
5 This file is part of the GNU MP Library.
6
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or (at your
10 option) any later version.
11
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 MA 02110-1301, USA. */
21
22 #include "config.h"
23
24 #include <stdio.h> /* for NULL */
25
26 #if HAVE_STDARG
27 #include <stdarg.h>
28 #else
29 #include <varargs.h>
30 #endif
31
32 #include "gmp.h"
33 #include "gmp-impl.h"
34
35 void
36 #if HAVE_STDARG
37 gmp_randinit (gmp_randstate_t rstate,
38               gmp_randalg_t alg,
39               ...)
40 #else
41 gmp_randinit (va_alist)
42      va_dcl
43 #endif
44 {
45   va_list ap;
46 #if HAVE_STDARG
47   va_start (ap, alg);
48 #else
49   __gmp_randstate_struct *rstate;
50   gmp_randalg_t alg;
51   va_start (ap);
52   rstate = va_arg (ap, __gmp_randstate_struct *);
53   alg = va_arg (ap, gmp_randalg_t);
54 #endif
55
56   switch (alg) {
57   case GMP_RAND_ALG_LC:
58     if (! gmp_randinit_lc_2exp_size (rstate, va_arg (ap, unsigned long)))
59       gmp_errno |= GMP_ERROR_INVALID_ARGUMENT;
60     break;
61   default:
62     gmp_errno |= GMP_ERROR_UNSUPPORTED_ARGUMENT;
63     break;
64   }
65   va_end (ap);
66 }