Blame tests/rand/t-iset.c

Packit 15dc08
/* Test gmp_randinit_set.
Packit 15dc08
Packit 15dc08
Copyright 2003 Free Software Foundation, Inc.
Packit 15dc08
Packit 15dc08
This file is part of the GNU MP Library test suite.
Packit 15dc08
Packit 15dc08
The GNU MP Library test suite is free software; you can redistribute it
Packit 15dc08
and/or modify it under the terms of the GNU General Public License as
Packit 15dc08
published by the Free Software Foundation; either version 3 of the License,
Packit 15dc08
or (at your option) any later version.
Packit 15dc08
Packit 15dc08
The GNU MP Library test suite is distributed in the hope that it will be
Packit 15dc08
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 15dc08
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Packit 15dc08
Public License for more details.
Packit 15dc08
Packit 15dc08
You should have received a copy of the GNU General Public License along with
Packit 15dc08
the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
Packit 15dc08
Packit 15dc08
#include <stdio.h>
Packit 15dc08
#include <stdlib.h>
Packit 15dc08
#include "gmp.h"
Packit 15dc08
#include "gmp-impl.h"
Packit 15dc08
#include "tests.h"
Packit 15dc08
Packit 15dc08
/* expect after a gmp_randinit_set that the new and old generators will
Packit 15dc08
   produce the same sequence of numbers */
Packit 15dc08
void
Packit 15dc08
check_one (const char *name, gmp_randstate_ptr src)
Packit 15dc08
{
Packit 15dc08
  gmp_randstate_t dst;
Packit 15dc08
  mpz_t  sz, dz;
Packit 15dc08
  int    i;
Packit 15dc08
Packit 15dc08
  gmp_randinit_set (dst, src);
Packit 15dc08
  mpz_init (sz);
Packit 15dc08
  mpz_init (dz);
Packit 15dc08
Packit 15dc08
  for (i = 0; i < 20; i++)
Packit 15dc08
    {
Packit 15dc08
      mpz_urandomb (sz, src, 123);
Packit 15dc08
      mpz_urandomb (dz, dst, 123);
Packit 15dc08
Packit 15dc08
      if (mpz_cmp (sz, dz) != 0)
Packit 15dc08
        {
Packit 15dc08
          printf     ("gmp_randinit_set didn't duplicate randstate\n");
Packit 15dc08
          printf     ("  algorithm: %s\n", name);
Packit 15dc08
          gmp_printf ("  from src:  %#Zx\n", sz);
Packit 15dc08
          gmp_printf ("  from dst:  %#Zx\n", dz);
Packit 15dc08
          abort ();
Packit 15dc08
        }
Packit 15dc08
    }
Packit 15dc08
Packit 15dc08
  mpz_clear (sz);
Packit 15dc08
  mpz_clear (dz);
Packit 15dc08
  gmp_randclear (dst);
Packit 15dc08
}
Packit 15dc08
Packit 15dc08
int
Packit 15dc08
main (int argc, char *argv[])
Packit 15dc08
{
Packit 15dc08
  tests_start ();
Packit 15dc08
Packit 15dc08
  call_rand_algs (check_one);
Packit 15dc08
Packit 15dc08
  tests_end ();
Packit 15dc08
  exit (0);
Packit 15dc08
}