[英]Fastest way to sample n random primes greater than p in Python?
I want to create a dateset of n primes greater than p ~ 2⁵⁰.我想创建一个大于 p ~ 2⁵⁰ 的 n 个素数的日期集。 I want these primes to not be consecutive but have some space in between so the difference between iᵗʰ and (i+1)ᵗʰ prime is not just a few bits.我希望这些素数不是连续的,但中间有一些空间,所以 iᵗʰ 和 (i+1)ᵗʰ 素数之间的区别不仅仅是几位。
I am using Sympy's randprime(low, hi)
in a loop,我在循环中使用 Sympy 的randprime(low, hi)
,
p = [start]
for i in range(n):
curr = int(randprime(start, 2 * start + 1))
p.append(curr)
start = curr
This gets significantly slow for n=10,000
.对于n=10,000
这会变得非常慢。 Is there a better (faster) way of accomplishing the prime sampling that I want?有没有更好(更快)的方法来完成我想要的素数采样?
Precompute (or just download ) a list of primes once and then sample the list during the runtime.预先计算(或只是下载)一个素数列表,然后在运行时对列表进行采样。
You can generate the list for 30x smaller upper bound than 2^50 (~10^15) with this algorithm: https://primes.utm.edu/nthprime/algorithm.php您可以使用此算法生成比 2^50(~10^15)小 30 倍的上限列表: https : //primes.utm.edu/nthprime/algorithm.php
I don't know how to get further with reasonable hardware setup.我不知道如何通过合理的硬件设置走得更远。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.