From:             chsnick at yahoo dot com
Operating system: Windows XP
PHP version:      5.0.0RC3
PHP Bug Type:     Math related
Bug description:  rand()%4  is cyclical

Description:
------------
rand()%4 is cyclical.  It proceeds from 0 to 1 to 2 to 3 to 0 to 1, etc.

Reproduce code:
---------------
srand(5);
for($i = 0; $i < 30; $i++)
        {
                $j = rand();
                $k = $j%4;
                echo "$k:$j<br>\n";
                
        }

Actual result:
--------------
2:14426
3:6795
0:22376
1:6017
2:38
3:21607
0:532
1:10941
2:30898
3:20483
0:11136
1:13753
2:28158
3:26975
0:32684
1:29813
2:27658
3:15483
0:27288
1:25329
2:16086
3:9559
0:6212
1:15661
2:29282
3:16371
0:29872
1:32553
2:21166
3:26703

-- 
Edit bug report at http://bugs.php.net/?id=28982&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28982&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28982&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28982&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28982&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28982&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28982&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28982&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28982&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28982&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28982&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28982&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28982&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28982&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28982&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28982&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28982&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28982&r=float

Reply via email to