Le mardi 23 juin 2020 20:33:11 UTC+2, slelievre a écrit :
>
> Not sure why one would want the "first pair" each time.
>
> Below we define a function that produces an iterator
> yielding random prime pairs one after the other,
> with primes picked at random in a range ensuring
> their product will have the correct number of digits.
>
> ```
> def prime_pair_for_each_product_ndigits(nmin, nmax):
>     for n in range(nmin, nmax + 1):
>         lo = isqrt(10**(n-1))
>         hi = isqrt(10**n)
>         a = random_prime(hi, lbound=lo)
>         b = random_prime(hi, lbound=lo)
>         yield a, b
> ```
>

This might give a product with one digit less
in extremely rare cases. To avoid that, replace

        lo = isqrt(10**(n-1))

with

        lo = isqrt(10**(n-1)) + 1


-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/701211f3-907f-4596-ad87-683df07fc485o%40googlegroups.com.

Reply via email to