| Something puzzling me in PHP rand() function |
sugarkane

msg:1308879 | 7:54 pm on Mar 26, 2001 (gmt 0) | A while ago I pinched a snippet of PHP from somewhere to use in a session id generator. It all worked fine, but as I was only just starting out in PHP I didn't investigate too deeply how it worked. This construct is now puzzling me:
$foo=rand()%(strlen($pool));
The effect is to choose a random number between zero and the character length of string $pool - yet I can't find any documentation on this form of rand() anywhere... the manual for PHP4 specifies rand(min_value, max_value) for this kind of thing. Does anyone know if this is a correct construct or a hangover from an earlier version of PHP?
|
Froggyman

msg:1308880 | 2:11 am on Mar 28, 2001 (gmt 0) | It's not a hangover. If no seed value is provided, the rand() function is automatically seeded with a value of 1.
|
sugarkane

msg:1308881 | 10:23 am on Mar 29, 2001 (gmt 0) | Thanks Froggyman. It's the % sign that puzzles me - I take it this is just a different method of specifying the maximum value?
|
|
|