Branch: Tag:

2003-06-10

2003-06-10 16:48:55 by Henrik Grubbström (Grubba) <grubba@grubba.org>

_random() now uses f_random_string() instead of mpz_random().
Fixes [bug 3458].

Rev: src/modules/Gmp/mpz_glue.c:1.150

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: mpz_glue.c,v 1.149 2003/05/19 19:23:41 mast Exp $ + || $Id: mpz_glue.c,v 1.150 2003/06/10 16:48:55 grubba Exp $   */      #include "global.h" - RCSID("$Id: mpz_glue.c,v 1.149 2003/05/19 19:23:41 mast Exp $"); + RCSID("$Id: mpz_glue.c,v 1.150 2003/06/10 16:48:55 grubba Exp $");   #include "gmp_machine.h"   #include "module.h"   
1804:   {    struct object *res = 0; /* Make gcc happy. */    pop_n_elems(args); +  args = 0;    if(mpz_sgn(THIS) <= 0)    Pike_error("Random on negative number.\n");    -  res=fast_clone_object(THIS_PROGRAM); -  /* We add two to assure reasonably uniform randomness */ -  mpz_random(OBTOMPZ(res), DO_NOT_WARN((int)(mpz_size(THIS) + 2))); +  push_object(res=fast_clone_object(THIS_PROGRAM)); +  /* We add four to assure reasonably uniform randomness */ +  push_int(mpz_size(THIS)*sizeof(mp_limb_t) + 4); +  f_random_string(1); +  if (sp[-1].type != T_STRING) { +  Pike_error("random_string(%d) returned non string.\n", +  mpz_size(THIS)*sizeof(mp_limb_t) + 4); +  } +  get_mpz_from_digits(OBTOMPZ(res), sp[-1].u.string, 256); +  pop_stack();    mpz_fdiv_r(OBTOMPZ(res), OBTOMPZ(res), THIS); /* modulo */ -  +  Pike_sp--; +  dmalloc_touch_svalue(Pike_sp);    PUSH_REDUCED(res);   }