wbhart / mpir

Multiple Precision Integers and Rationals
GNU General Public License v3.0
229 stars 135 forks source link

Added get_randstate_t method to gmp_randclass #260

Closed qxzkjp closed 6 years ago

qxzkjp commented 6 years ago

We have mpz_class::get_mpz_t, mpf_class::get_mpf_t, etc. which enable us to use those wrapper classes with C API functions that have no OO equivalent, without having to sacrifice memory safety. I have added an analogous method to gmp_randclass, to enable me to use it with mpz_likely_prime_p, and I thought that this might be a modification that is generally useful.

wbhart commented 6 years ago

This seems useful. Is there any chance you could document it and add a test function.

qxzkjp commented 6 years ago

Of course, I should be able to do that by the end of the week.

qxzkjp commented 6 years ago

I've added a test and some documentation with a simple example.

I was a bit unsure of how to test this, but I settled on creating two gmp_randclasses, and seeding one with it's seed method, and one by calling get_randstate_t and feeding it into gmp_randseed_ui, then checking if they return the same stream of random numbers. This should ensure that the thing returned from get_randstate_t is the real underlying state.

wbhart commented 6 years ago

Thanks for this contribution!