Branch: Tag:

1999-10-26

1999-10-26 00:09:44 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

Gmp.mpz->random() implemented

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

4:   ||| See the files COPYING and DISCLAIMER for more information.   \*/   #include "global.h" - RCSID("$Id: mpz_glue.c,v 1.53 1999/10/25 10:20:26 hubbe Exp $"); + RCSID("$Id: mpz_glue.c,v 1.54 1999/10/26 00:09:44 hubbe Exp $");   #include "gmp_machine.h"      #if defined(HAVE_GMP2_GMP_H) && defined(HAVE_LIBGMP2)
985:    PUSH_REDUCED(res);   }    + static void mpzmod_random(INT32 args) + { +  struct object *res; +  pop_n_elems(args); +  if(mpz_sgn(THIS) <= 0) +  error("random on negative number.\n"); +  +  res=clone_object(mpzmod_program,0); +  /* We add two to assure reasonably uniform randomness */ +  mpz_random(OBTOMPZ(res), mpz_size(OBTOMPZ(res)) + 2); +  mpz_fdiv_r(OBTOMPZ(res), OBTOMPZ(res), THIS); /* modulo */ +  PUSH_REDUCED(res); + } +    static void init_mpz_glue(struct object *o)   {    mpz_init(THIS);
1103:    /* function(void:int) */    ADD_FUNCTION("popcount", mpzmod_popcount,tFunc(tVoid,tInt), 0);    +  ADD_FUNCTION("_random",mpzmod_random,tFunc(tNone,tObj),0); +    #if 0    /* These are not implemented yet */    /* function(:int) */
1114:    set_init_callback(init_mpz_glue);    set_exit_callback(exit_mpz_glue);    +     id=add_program_constant("mpz", mpzmod_program=end_program(), 0);       /* function(int, int:object) */
1121:    /* function(int:object) */    ADD_FUNCTION("fac", gmp_fac,tFunc(tInt,tObj), 0);    -  +    #ifdef AUTO_BIGNUM    {    /* Alert bignum.c that we have been loaded /Hubbe */