Make WordPress Core

Opened 14 years ago

Closed 2 years ago

Last modified 2 years 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:

Description

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
14 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
3 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.


3 years ago
#4

  • Keywords has-patch added

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

Trac ticket: https://core.trac.wordpress.org/ticket/15089

#5 @neychok
3 years ago

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

#6 @sabernhardt
2 years 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
2 years ago

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

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


2 years ago
#8

  • Keywords needs-refresh removed

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

Trac ticket: https://core.trac.wordpress.org/ticket/15089

#9 @neychok
2 years ago

Hey @desrosj, I just refreshed my PR. 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!

Version 0, edited 2 years ago by neychok (next)

#10 @sabernhardt
2 years 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.


2 years ago

#12 @audrasjb
2 years 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
2 years 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.