@@ -1377,7 +1377,7 @@ PHP_FUNCTION(range)
1377
1377
1378
1378
1379
1379
static int array_data_shuffle (const void * a , const void * b ) {
1380
- return ( php_rand () % 2 ) ? 1 : -1 ;
1380
+ return php_rand_range ( 0 , 1 ) ? 1 : -1 ;
1381
1381
}
1382
1382
1383
1383
@@ -2716,18 +2716,18 @@ PHP_FUNCTION(array_multisort)
2716
2716
2717
2717
/* {{{ proto mixed array_rand(array input [, int num_req])
2718
2718
Return key/keys for random entry/entries in the array */
2719
+
2720
+ /* FIXME:The algorithm used is bogus! */
2719
2721
PHP_FUNCTION (array_rand )
2720
2722
{
2721
2723
zval * * input , * * num_req ;
2722
- long randval ;
2724
+ double randval ;
2723
2725
int num_req_val , num_avail , key_type ;
2724
2726
char * string_key ;
2725
2727
uint string_key_len ;
2726
2728
ulong num_key ;
2727
2729
HashPosition pos ;
2728
2730
2729
- php_error (E_ERROR , "Function array_rand temporarily disabled" );
2730
-
2731
2731
if (ZEND_NUM_ARGS () < 1 || ZEND_NUM_ARGS () > 2 ||
2732
2732
zend_get_parameters_ex (ZEND_NUM_ARGS (), & input , & num_req ) == FAILURE ) {
2733
2733
WRONG_PARAM_COUNT ;
@@ -2760,20 +2760,10 @@ PHP_FUNCTION(array_rand)
2760
2760
zend_hash_internal_pointer_reset_ex (Z_ARRVAL_PP (input ), & pos );
2761
2761
while (num_req_val && (key_type = zend_hash_get_current_key_ex (Z_ARRVAL_PP (input ), & string_key , & string_key_len , & num_key , 0 , & pos )) != HASH_KEY_NON_EXISTANT ) {
2762
2762
2763
- #ifdef HAVE_RANDOM
2764
- randval = random ();
2765
- #else
2766
- #ifdef HAVE_LRAND48
2767
- randval = lrand48 ();
2768
- #else
2769
- randval = rand ();
2770
- #endif
2771
- #endif
2772
2763
2773
- /* TEMPORARY HACK TO GET IT COMPILE */
2774
- #define PHP_RAND_MAX 1
2775
2764
2776
- if ((double )(randval /(PHP_RAND_MAX + 1.0 )) < (double )num_req_val /(double )num_avail ) {
2765
+ randval = php_drand ();
2766
+ if (randval < (double )num_req_val /(double )num_avail ) {
2777
2767
/* If we are returning a single result, just do it. */
2778
2768
if (Z_TYPE_P (return_value ) != IS_ARRAY ) {
2779
2769
if (key_type == HASH_KEY_IS_STRING ) {
0 commit comments