~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to src/gmp/mpf/urandomb.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2007-04-09 11:51:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070409115151-ql8cr0kalzx1jmla
Tags: 0.9i-20070324-2
Upload to unstable. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
You should have received a copy of the GNU Lesser General Public License
21
21
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
22
 
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23
 
MA 02111-1307, USA. */
 
22
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
23
MA 02110-1301, USA. */
24
24
 
25
25
#include "gmp.h"
26
26
#include "gmp-impl.h"
31
31
  mp_ptr rp;
32
32
  mp_size_t nlimbs;
33
33
  mp_exp_t exp;
34
 
 
35
 
  nbits = MIN (nbits, __GMPF_PREC_TO_BITS (rop->_mp_prec));
 
34
  mp_size_t prec;
36
35
 
37
36
  rp = PTR (rop);
38
 
  nlimbs = (nbits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS;
 
37
  nlimbs = BITS_TO_LIMBS (nbits);
 
38
  prec = PREC (rop);
 
39
 
 
40
  if (nlimbs > prec + 1 || nlimbs == 0)
 
41
    {
 
42
      nlimbs = prec + 1;
 
43
      nbits = nlimbs * GMP_NUMB_BITS;
 
44
    }
39
45
 
40
46
  _gmp_rand (rp, rstate, nbits);
41
47
 
42
48
  /* If nbits isn't a multiple of GMP_NUMB_BITS, shift up.  */
43
 
  if (nlimbs != 0)
44
 
    {
45
 
      if (nbits % GMP_NUMB_BITS != 0)
46
 
        mpn_lshift (rp, rp, nlimbs, GMP_NUMB_BITS - nbits % GMP_NUMB_BITS);
47
 
    }
 
49
  if (nbits % GMP_NUMB_BITS != 0)
 
50
    mpn_lshift (rp, rp, nlimbs, GMP_NUMB_BITS - nbits % GMP_NUMB_BITS);
48
51
 
49
52
  exp = 0;
50
53
  while (nlimbs != 0 && rp[nlimbs - 1] == 0)