Skip to content

fix: random pick can reach the last issue - #1101

Open
yugaaank wants to merge 1 commit into
cutenode:masterfrom
yugaaank:fix/random-pick-last-issue
Open

fix: random pick can reach the last issue#1101
yugaaank wants to merge 1 commit into
cutenode:masterfrom
yugaaank:fix/random-pick-last-issue

Conversation

@yugaaank

Copy link
Copy Markdown

Fixes #1100

What

Random issue selection used:
```js
Math.floor(Math.random() * Math.floor(issues.length - 1))
```
The inner `Math.floor(issues.length - 1)` bounded the multiplier so `issues[issues.length - 1]` was never reachable.

Change

```js
const key = cmd.first ? 0 : Math.floor(Math.random() * issues.length)
```
Every returned issue now has an equal chance of being picked, including the last. The inner `Math.floor` was also redundant since `issues.length` is already an integer.

Test

Added `tests/pick.spec.js` guarding the selection bounds (first flag → 0; random pick reaches both first and last index, never out of range). Full `npm test` passes (standard + jest, 100% coverage on touched code).

Random selection used Math.floor(Math.random() * Math.floor(issues.length - 1)),
which made the final issue unreachable. Now uses issues.length so every result
has an equal chance of being picked.

Fixes cutenode#1100

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random pick never returns the last issue

1 participant