X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/92c2a29042b4e2b5b4429f9848dc22fd92acb0d8..893c6259cd5d374f540e54def522dcd251c4c503:/mprand.h?ds=inline diff --git a/mprand.h b/mprand.h new file mode 100644 index 00000000..2ecfa152 --- /dev/null +++ b/mprand.h @@ -0,0 +1,81 @@ +/* -*-c-*- + * + * $Id: mprand.h,v 1.1 1999/12/10 23:23:05 mdw Exp $ + * + * Generate a random multiprecision integer + * + * (c) 1999 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of Catacomb. + * + * Catacomb is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Catacomb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with Catacomb; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +/*----- Revision history --------------------------------------------------* + * + * $Log: mprand.h,v $ + * Revision 1.1 1999/12/10 23:23:05 mdw + * Support for generating random large integers. + * + */ + +#ifndef CATACOMB_MPRAND_H +#define CATACOMB_MPRAND_H + +#ifdef __cplusplus + extern "C" { +#endif + +/*----- Header files ------------------------------------------------------*/ + +#ifndef CATACOMB_GRAND_H +# include "grand.h" +#endif + +#ifndef CATACOMB_MP_H +# include "mp.h" +#endif + +/*----- Functions provided ------------------------------------------------*/ + +/* --- @mprand@ --- * + * + * Arguments: @mp *d@ = destination integer + * @unsigned b@ = number of bits + * @grand *r@ = pointer to random number source + * @mpw or@ = mask to OR with low-order bits + * + * Returns: A random integer with the requested number of bits + * + * Use: Constructs an arbitrarily large pseudorandom integer. + * Assuming that the generator @r@ is good, the result is + * uniformly distributed in the interval %$[2^{b - 1}, 2^b)$%. + * The result is then ORred with the given @or@ value. This + * will often be 1, to make the result odd. + */ + +extern mp *mprand(mp */*d*/, unsigned /*b*/, grand */*r*/, mpw /*or*/); + +/*----- That's all, folks -------------------------------------------------*/ + +#ifdef __cplusplus + } +#endif + +#endif