Skip to content

Commit c4d412a

Browse files
committed
Fix: Update RAND() UDF to support seeds and return floats, solving MySQL compatibility and SQLite argument mismatch
1 parent 3afb1e8 commit c4d412a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

wp-includes/sqlite/class-wp-sqlite-pdo-user-defined-functions.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,15 @@ public function md5( $field ) {
176176
* This function uses mt_rand() which is four times faster than rand() and returns
177177
* the random number between 0 and 1.
178178
*
179-
* @return int
179+
* @param int|null $seed The seed value (optional).
180+
*
181+
* @return float
180182
*/
181-
public function rand() {
182-
return mt_rand( 0, 1 );
183+
public function rand( $seed = null ) {
184+
if ( null !== $seed ) {
185+
mt_srand( intval( $seed ) );
186+
}
187+
return mt_rand( 0, mt_getrandmax() ) / mt_getrandmax();
183188
}
184189

185190
/**

0 commit comments

Comments
 (0)