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 something like the following.

```
sage: p_q_list = list(prime_pair_for_each_product_ndigits(19, 35))
sage: p_q_list
[(2257885207, 1029222697),
 (7906953709, 8831254513),
 (28123041337, 18086888887),
 (59156603659, 75212477107),
 (244478980829, 297135812329),
 (878180166047, 926189502323),
 (1390098443147, 1010518243127),
 (5150835567223, 3603512345189),
 (16533079879703, 15727405198679),
 (34437803922611, 57693414719911),
 (102979771890571, 141205565889301),
 (941693653240727, 468548529571597),
 (1375078260756671, 1726461802816903),
 (8524331332200121, 4310462307066121),
 (19014345158785303, 31601933129557883),
 (92121426759262499, 64338223205154251),
 (262242817443146321, 251117727289363427)]
```

We check the number of digits of each product.

```
sage: f = lambda n: f'{n:36d} has {n.ndigits():2d} digits'
sage: print('\n'.join(f(n) for n in (p*q for p, q in p_q_list)))
                 2323866702264943279 has 19 digits
                69828320626688338717 has 20 digits
               508658323826826921919 has 21 digits
              4449314698430409934513 has 22 digits
             72643460565990932840741 has 23 digits
            813361250941000432227181 has 24 digits
           1404719836542484333000669 has 25 digits
          18561099554526665790140147 has 26 digits
         260022446450216138134512337 has 27 digits
        1986834503750174243684807621 has 28 digits
       14541316964959210349671680871 has 29 digits
      441229176532847985852022831019 has 30 digits
     2374020093080293654628048809913 has 31 digits
    36743808900391354263355551200641 has 32 digits
   600890064210265812194221708193549 has 33 digits
  5926928916814700284047132294733249 has 34 digits
 65853820314282336219416564107002067 has 35 digits
```

-- 
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/a507a76b-5555-451b-ac7e-1162bb46d58an%40googlegroups.com.

Reply via email to