Annotation of OpenXM_contrib/gmp/randlc2x.c, Revision 1.1
1.1 ! maekawa 1: /* gmp_randinit_lc_2exp (state, a, c, m2exp) -- Initialize random
! 2: state STATE for a linear congruential generator with multiplier A,
! 3: adder C, and modulus 2 ^ M2EXP.
! 4:
! 5: Copyright (C) 2000 Free Software Foundation, Inc.
! 6:
! 7: This file is part of the GNU MP Library.
! 8:
! 9: The GNU MP Library is free software; you can redistribute it and/or modify
! 10: it under the terms of the GNU Lesser General Public License as published by
! 11: the Free Software Foundation; either version 2.1 of the License, or (at your
! 12: option) any later version.
! 13:
! 14: The GNU MP Library is distributed in the hope that it will be useful, but
! 15: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 16: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
! 17: License for more details.
! 18:
! 19: You should have received a copy of the GNU Lesser General Public License
! 20: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
! 21: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
! 22: MA 02111-1307, USA. */
! 23:
! 24: #include "gmp.h"
! 25: #include "gmp-impl.h"
! 26:
! 27: void
! 28: #if __STDC__
! 29: gmp_randinit_lc_2exp (gmp_randstate_t rstate,
! 30: mpz_t a,
! 31: unsigned long int c,
! 32: unsigned long int m2exp)
! 33: #else
! 34: gmp_randinit_lc_2exp (rstate, a, c, m2exp)
! 35: gmp_randstate_t rstate;
! 36: mpz_t a;
! 37: unsigned long int c;
! 38: unsigned long int m2exp;
! 39: #endif
! 40: {
! 41: mpz_init_set_ui (rstate->seed, 1);
! 42: _mpz_realloc (rstate->seed, m2exp / BITS_PER_MP_LIMB
! 43: + (m2exp % BITS_PER_MP_LIMB != 0));
! 44:
! 45: /* Allocate algorithm specific data. */
! 46: rstate->algdata.lc = (__gmp_randata_lc *)
! 47: (*_mp_allocate_func) (sizeof (__gmp_randata_lc));
! 48:
! 49: mpz_init_set (rstate->algdata.lc->a, a);
! 50: rstate->algdata.lc->c = c;
! 51:
! 52: /* Cover weird case where m2exp is 0, which means that m is used
! 53: instead of m2exp. */
! 54: if (m2exp == 0)
! 55: mpz_init_set_ui (rstate->algdata.lc->m, 0);
! 56: rstate->algdata.lc->m2exp = m2exp;
! 57:
! 58: rstate->alg = GMP_RAND_ALG_LC;
! 59: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>