Reduce likelyhood of generated number conflicts - #1007
Merged
Conversation
By using the non-secure random generator, and caching the class that may be forked in Puma, we're making conflicts more likely. This is still a possibility of collisions - we've almost used 1% of available codes, however this might reduce the change. I've removed the random number seed as part of this - SecureRandom can't be seeded in the same way. Looking at the commit history, this was a tool to help make test runs more deterministic but isn't required. If we do, we should add the ability to swap out random number generators.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The updated randomness approach makes the existing “different code each time” spec effectively non-reproducible and probabilistic, increasing the risk of rare flaky CI failures.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Updates ForEducation code generation to avoid RNG state collisions across forked app workers (similar to the SecureRandom change previously made for join codes).
Changes:
- Switch
ForEducationCodeGeneratorfrom a sharedRandominstance toSecureRandom.random_number. - Remove the RSpec suite seed-based initialization of
ForEducationCodeGenerator.random. - Update the generator spec to stub
SecureRandom.random_numberinstead ofRandom#rand.
File summaries
| File | Description |
|---|---|
| lib/for_education_code_generator.rb | Replace shared Random usage with SecureRandom for fork-safe randomness. |
| spec/lib/for_education_code_generator_spec.rb | Update unit test to stub SecureRandom; (note: one test should be made deterministic to avoid rare flakiness). |
| spec/support/for_education_code_generator.rb | Remove suite-level seeding/configuration for the old injectable RNG. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Test coverage93.57% line coverage reported by SimpleCov. |
raspberrypiherokubot
temporarily deployed
to
editor-api-p-reduce-cla-og9nyr
September 8, 2026 15:18
Inactive
jamiebenstead
approved these changes
Sep 8, 2026
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.
Status
What's changed?
Switch to using the SecureRandom generator. This is an approach similar to taken for Join Codes in #952
See commit for more.