Primality test function doesn't work on large numbers?
Eugene Wissner via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 10 12:08:03 PST 2017
On Tuesday, 10 January 2017 at 03:02:40 UTC, Elronnd wrote:
> Thank you! Would you mind telling me what you changed aside
> from pow() and powm()? diff isn't giving me readable results,
> since there was some other stuff I trimmed out of the original
> file. Also, while this is a *lot* better, I still get some lag
> generating 1024-bit primes and I can't generate larger primes
> in a reasonable amount of time. Maybe my genbigint() function
> is to blame? It isn't efficient:
>
> bigint genbigint(int numbits) {
> bigint tmp;
> while (numbits --> 0) {
> tmp <<= 1;
> tmp += uniform(0, 2);
> }
> return tmp;
> }
Yes. You would normally get some random string/value only once
and then apply md5 or better sha512 on it (several times if you
want to have a more secur hash) to get the right length and then
get the hex digest and load it into bigint.
More information about the Digitalmars-d-learn
mailing list