Professional Web Applications Themes

#24909 [Fbk->Opn]: rand function with range always returns low value of range - PHP Development

ID: 24909 User updated by: a0 at hush dot com Reported By: a0 at hush dot com -Status: Feedback +Status: Open Bug Type: Math related Operating System: solaris 8 PHP Version: 4.3.2 New Comment: thanks for the response. i have downloaded 4.3.3RC2 and tried it. first, i configured it using no args. after i compiled it, the rand() function behaves as expected, even with a range specified. this works. i then configured it with --with-nsapi=/usr/local/iws41, which is what we need to use the module with our webserver. after i compiled it, the cli program now returns a 0 whenever a ...

  1. #1

    Default #24909 [Fbk->Opn]: rand function with range always returns low value of range

    ID: 24909
    User updated by: a0 at hush dot com
    Reported By: a0 at hush dot com
    -Status: Feedback
    +Status: Open
    Bug Type: Math related
    Operating System: solaris 8
    PHP Version: 4.3.2
    New Comment:

    thanks for the response.

    i have downloaded 4.3.3RC2 and tried it.

    first, i configured it using no args. after i compiled
    it, the rand() function behaves as expected, even with
    a range specified. this works.

    i then configured it with --with-nsapi=/usr/local/iws41,
    which is what we need to use the module with our
    webserver. after i compiled it, the cli program now
    returns a 0 whenever a range is specified to rand().

    i have not really looked through the code, but i would
    guess this has something to do with the fact that php
    is built with -DZTS in the second scenario (a different
    random function is used in rand.c when this is
    defined).


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-08-02 12:46:58] [email]iliaaphp.net[/email]

    I've asked a number of people to te the problem, however they
    were unable to do so using latest PHP and Solaris 8 & 9. Please try the
    latest snapshot of 4.3.3 and see if the problem persists.

    ------------------------------------------------------------------------

    [2003-08-01 14:37:22] a0 at hush dot com

    Description:
    ------------
    when using the rand function with php 4.3.2 on solaris 8, it will
    return a random value as expected if no range is specified. if a
    range
    is specified it will always return the low value of the range.

    i'm building the module with -DZTS, and it is being loaded into
    IWS4.1.

    i've modified the code so it works by changing line 36 of
    php_rand.h from
    #if HAVE_LRAND48
    to
    #if (HAVE_LRAND48 && !sun)
    so PHP_RAND_MAX will get a value of RAND_MAX.

    Reproduce code:
    ---------------
    <?
    $r = rand();
    echo "$r\n";
    $r = rand(0, 100);
    echo "$r\n";
    ?>


    Expected result:
    ----------------
    24384
    0

    (it will always return 0)



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=24909&edit=1[/url]

    a0 at hush dot com Guest

  2. #2

    Default #24909 [Fbk->Opn]: rand function with range always returns low value of range

    ID: 24909
    User updated by: a0 at hush dot com
    Reported By: a0 at hush dot com
    -Status: Feedback
    +Status: Open
    Bug Type: Math related
    Operating System: solaris 8
    PHP Version: 4.3.2
    New Comment:

    i used the cli binary in both cases


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-08-02 15:00:52] [email]iliaaphp.net[/email]

    I've tried the ZTS version on both Linux & Windows and it worked
    perfectly in both cases. Did you run test via the nsapi module or using
    PHP cli or cgi binaries?

    ------------------------------------------------------------------------

    [2003-08-02 13:55:00] a0 at hush dot com

    thanks for the response.

    i have downloaded 4.3.3RC2 and tried it.

    first, i configured it using no args. after i compiled
    it, the rand() function behaves as expected, even with
    a range specified. this works.

    i then configured it with --with-nsapi=/usr/local/iws41,
    which is what we need to use the module with our
    webserver. after i compiled it, the cli program now
    returns a 0 whenever a range is specified to rand().

    i have not really looked through the code, but i would
    guess this has something to do with the fact that php
    is built with -DZTS in the second scenario (a different
    random function is used in rand.c when this is
    defined).

    ------------------------------------------------------------------------

    [2003-08-02 12:46:58] [email]iliaaphp.net[/email]

    I've asked a number of people to te the problem, however they
    were unable to do so using latest PHP and Solaris 8 & 9. Please try the
    latest snapshot of 4.3.3 and see if the problem persists.

    ------------------------------------------------------------------------

    [2003-08-01 14:37:22] a0 at hush dot com

    Description:
    ------------
    when using the rand function with php 4.3.2 on solaris 8, it will
    return a random value as expected if no range is specified. if a
    range
    is specified it will always return the low value of the range.

    i'm building the module with -DZTS, and it is being loaded into
    IWS4.1.

    i've modified the code so it works by changing line 36 of
    php_rand.h from
    #if HAVE_LRAND48
    to
    #if (HAVE_LRAND48 && !sun)
    so PHP_RAND_MAX will get a value of RAND_MAX.

    Reproduce code:
    ---------------
    <?
    $r = rand();
    echo "$r\n";
    $r = rand(0, 100);
    echo "$r\n";
    ?>


    Expected result:
    ----------------
    24384
    0

    (it will always return 0)



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=24909&edit=1[/url]

    a0 at hush dot com Guest

Similar Threads

  1. #39464 [NEW]: Range function produces odd values in foreach loop
    By netnessie at gmail dot com in forum PHP Bugs
    Replies: 1
    Last Post: November 10th, 04:25 PM
  2. value out of range
    By JamieCrow in forum Macromedia Director 3D
    Replies: 5
    Last Post: December 6th, 06:47 PM
  3. Replies: 1
    Last Post: August 2nd, 08:00 PM
  4. #24909 [NEW]: rand function with range always returns low value of range
    By a0 at hush dot com in forum PHP Development
    Replies: 0
    Last Post: August 1st, 07:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139