Make WordPress Core

Opened 14 years ago

Closed 20 months ago

Last modified 20 months ago

#15089 closed defect (bug) (fixed)

wp_rand() can be asked for negative numbers but will never return them

Reported by: hakre's profile hakre Owned by: audrasjb's profile audrasjb
Milestone: 6.1 Priority: lowest
Severity: minor Version: 2.6
Component: General Keywords: good-first-bug has-patch commit
Focuses: docs Cc:


wp_rand() has a min and a max parameter to address a wish which number to get back.

Unfourtionatly the function is unable to handle negative numbers w/o having this documented.

Change History (14)

#1 @hakre
14 years ago

Related: #15090

#2 @westi
13 years ago

  • Component changed from General to Inline Docs
  • Milestone Awaiting Review deleted
  • Priority changed from normal to lowest
  • Resolution set to maybe later
  • Severity changed from normal to trivial
  • Status changed from new to closed

No patch and no traction closing for now.

#3 @jeremyfelt
2 years ago

  • Focuses docs added
  • Keywords good-first-bug added
  • Milestone set to Awaiting Review
  • Resolution maybelater deleted
  • Status changed from closed to reopened
  • Version changed from 3.0 to 2.6

It's a little confusing that wp_rand() will not return a negative integer. I think it would be worth adding a short note the function docs, especially now that it's mostly a wrapper of random_int(), which will return negative integers.

This ticket was mentioned in PR #2305 on WordPress/wordpress-develop by Neychok.

2 years ago

  • Keywords has-patch added

A slight change in the wp_rand() docs indicating that it only returns non-negative numbers.

Trac ticket:

#5 @neychok
2 years ago

Hey guys, this is my first patch. I hope I submitted it like you are supposed to.

#6 @sabernhardt
21 months ago

  • Component changed from Inline Docs to General
  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to 6.1
  • Severity changed from trivial to minor

Thanks for creating a patch!

It needs to be refreshed after the commits on #55194.

#7 @desrosj
20 months ago

Hi @neychok, are you able to refresh your PR?

This ticket was mentioned in PR #3265 on WordPress/wordpress-develop by Neychok.

20 months ago

  • Keywords needs-refresh removed

Changed the doc comment of the wp_rand() function to indicate that it only returns positive numbers.

Trac ticket:

#9 @neychok
20 months ago

Hey @desrosj, I just created a new PR with the updated patch. I closed the last one by mistake while syncing my fork.

I also changed the "A random non-negative number" to "A random positive number" from my last PR because at the time of my last PR the function was able to return a Zero.

Thank you for looking into this patch!

Last edited 20 months ago by neychok (previous) (diff)

#10 @sabernhardt
20 months ago

Sorry for not being clear: the patch needed a refresh because lines around your changes were edited. The function can return zero (now), so "non-negative" should be correct.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.

20 months ago

#12 @audrasjb
20 months ago

  • Keywords commit added
  • Owner set to audrasjb
  • Status changed from reopened to accepted

I added a commit to the above PR to replace "positive" with "non-negative".

Self assigning for commit.

#13 @audrasjb
20 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 54190:

Docs: Update wp_rand docblock to clarify that it returns a non-negative number.

Props hakre, westi, jeremyfelt, neychok, sabernhardt, audrasjb.
Fixes #15089.

Note: See TracTickets for help on using tickets.