-
Notifications
You must be signed in to change notification settings - Fork 177
feat(math.py): Add the functionality to generate a random prime number within a specified range #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Conversation
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
...andom primes within a range
@weilycoder
weilycoder
changed the title
(削除) 增加在指定范围内随机质数的功能 (削除ここまで)
(追記) feat(math.py): 增加在指定范围内随机质数的功能 (追記ここまで)
Feb 16, 2025
Open
@weilycoder
weilycoder
changed the title
(削除) feat(math.py): 增加在指定范围内随机质数的功能 (削除ここまで)
(追記) feat(math.py): Add the functionality to generate a random prime number within a specified range (追記ここまで)
Feb 16, 2025
@Mr-Python-in-China
Mr-Python-in-China
force-pushed
the
master
branch
3 times, most recently
from
June 30, 2025 15:49
2f520f5 to
7056a5a
Compare
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.
Uh oh!
There was an error while loading. Please reload this page.
Update2: 另外,相关函数放在 math.py 中是否合理?
算法不保证均匀随机,如果追求区间内每个质数被选中的概率相等,可以使用
prime_sieve预处理质数表再使用random库中的choice函数。具体流程如下:
Update: 已经对函数进行测试,与暴力查找进行了对拍,似乎没有问题
我为此实现的3ドル$ 的质数都是 6ドルn\pm 1$ 型的定理,逻辑略复杂)。
nextprime和prevprime都未经严格测试,大家可以先 review 一下(使用了大于(削除) 测试还没写,一会补上。 (削除ここまで)