feat(math.py): Add the functionality to generate a random prime number within a specified range #164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update2: 另外,相关函数放在 math.py 中是否合理?
算法不保证均匀随机,如果追求区间内每个质数被选中的概率相等,可以使用
prime_sieve
预处理质数表再使用random
库中的choice
函数。具体流程如下:
Update: 已经对函数进行测试,与暴力查找进行了对拍,似乎没有问题
我为此实现的$3$ 的质数都是 $6n\pm 1$ 型的定理,逻辑略复杂)。
nextprime
和prevprime
都未经严格测试,大家可以先 review 一下(使用了大于测试还没写,一会补上。