|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-07-14 19:21 UTC] moriyoshi@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
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