feat(math.py): Add the functionality to generate a random prime number within a specified range#164
Open
weilycoder wants to merge 4 commits intoluogu-dev:masterfrom
Open
feat(math.py): Add the functionality to generate a random prime number within a specified range#164weilycoder wants to merge 4 commits intoluogu-dev:masterfrom
weilycoder wants to merge 4 commits intoluogu-dev:masterfrom
Conversation
…andom primes within a range
Open
2f520f5 to
7056a5a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 一下(使用了大于测试还没写,一会补上。