[wp-trac] [WordPress Trac] #55194: wp_rand( 0, 0) result in random integer

WordPress Trac noreply at wordpress.org
Fri Feb 18 15:20:26 UTC 2022


#55194: wp_rand( 0, 0)  result in random integer
--------------------------+---------------------
 Reporter:  mlajo         |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  6.0
Component:  General       |     Version:  5.9
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  docs
--------------------------+---------------------

Comment (by SergeyBiryukov):

 Replying to [comment:6 mlajo]:
 > Replying to [comment:3 SergeyBiryukov]:
 > > This is also consistent with `mt_rand()`, which returns a random
 integer and not 0 when parameters are omitted.
 >
 > mt_rand( 0, 0 ) returns 0

 Indeed, thanks! I meant `mt_rand()` without any parameters, in that case
 `$max` defaults to `mt_getrandmax()`.

 I guess `wp_rand()` too should have used `null` as the default value for
 both parameters, so that we could differentiate between `wp_rand()` and
 `wp_rand( 0, 0 )`, which is not currently possible as zero is the default
 value. But it's too late to change that now without security implications.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55194#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list