Skip to content

test(build): simplify generateRandomDebugPort()#462

Open
CryptoJones wants to merge 1 commit into
masterfrom
fix/454-debug-port-generator
Open

test(build): simplify generateRandomDebugPort()#462
CryptoJones wants to merge 1 commit into
masterfrom
fix/454-debug-port-generator

Conversation

@CryptoJones

Copy link
Copy Markdown
Owner

Closes #454.

generateRandomDebugPort() drew a full 32-bit int, XOR-folded the high bytes down into the low 8 bits over a 4-iteration loop, then masked with 0xff — a roundabout way to obtain a uniform 0..255.

Replaced with:

return 18300 + java.util.concurrent.ThreadLocalRandom.current().nextInt(256)

nextInt(256) draws 0..255 uniformly in one call (fully-qualified name avoids adding an import to the script). The port range is unchanged: 18300 + (0..255) = [18300, 18555], matching the original comment and well clear of the 1024..65535 bounds.

Verified the range holds over 100k draws.

🤖 Generated with Claude Code

The old implementation drew a full 32-bit int, XOR-folded the high bytes
down into the low 8 bits across a 4-iteration loop, then masked to
0xff — an obfuscated way to get a uniform 0..255. Replace it with
ThreadLocalRandom.current().nextInt(256), which draws 0..255 uniformly
in one call.

Range is unchanged: 18300 + (0..255) = [18300, 18555], matching the
original comment and well clear of the 1024..65535 bounds. Verified the
range over 100k draws.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the lane:framework Default lane: anything else. label Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lane:framework Default lane: anything else.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random debug-port generator has weak mixing / overcomplex loop

1 participant