Skip to content

Fix rand() range constraint to use abs() for reversed parameters#5264

Merged
Girgias merged 1 commit intophp:masterfrom
lacatoire:fix/rand-abs-range-constraint
Feb 6, 2026
Merged

Fix rand() range constraint to use abs() for reversed parameters#5264
Girgias merged 1 commit intophp:masterfrom
lacatoire:fix/rand-abs-range-constraint

Conversation

@lacatoire
Copy link
Contributor

Summary

  • Fix the range constraint in rand() notes from (max - min) <= getrandmax() to abs(max - min) <= getrandmax()
  • Since rand() accepts max smaller than min (unlike mt_rand()), the absolute value is
    required

Fixes #3890

@lacatoire lacatoire requested a review from TimWolla as a code owner February 5, 2026 11:02
@Girgias Girgias merged commit a2a3f35 into php:master Feb 6, 2026
2 checks passed
@lacatoire lacatoire deleted the fix/rand-abs-range-constraint branch February 6, 2026 14:00
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.

Error in documentation for rand()

3 participants