gmp_randseed()
bom brill
bombrill_gmp@yahoo.fr
Wed, 18 Dec 2002 19:57:03 +0100 (CET)
I have a real problem understanding the role of the
gmp_randseed(), and its implementation.
In order to understand how does that function works, I
want to create a program that generates some random
numbers.
So here is what I did :
#include <stdio.h>
#include <gmp.h>
#include <unistd.h>
/* le but de ce programme est de pondre un nombre
aleatoire */
int main(int argc, char **argv)
{
gmp_randstate_t state;
mpz_t nbre1, nbre2, seed;
while(1)
{
/* Initialisation */
mpz_init(nbre1);
mpz_init(nbre2);
mpz_init(seed);
gmp_randinit_default(state);
mpz_init_set_str(seed, "2^256", 10);
gmp_randseed(state, seed);
mpz_urandomb(nbre1, state, 256);
mpz_urandomb(nbre2, state, 256);
/* Affichage */
gmp_printf(" nbre1 : %Zd \n nbre2 : %Zd\n",
nbre1, nbre2);
printf(" ---------------------- \n");
/* Nettoyage */
gmp_randclear(state);
mpz_clear(nbre1);
mpz_clear(nbre2);
mpz_clear(seed);
}
return 0;
}
But it doesn t work as I expected. In fact, the
numbers are always the same !
So, if there is someone who wants to explain me,
first, what is the concept behind the "state", what is
the role of the seed fuction, and eventually, what do
I have to do, to make my program run as I want to.
Really thx for your help, and sorry for my english..
but I m french.
Jeremie
___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com