Welcome to WebmasterWorld Guest from 54.205.88.118

Forum Moderators: coopster & jatar k

Something puzzling me in PHP

rand() function

   
7:54 pm on Mar 26, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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?

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.
10:23 am on Mar 29, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Froggyman. It's the % sign that puzzles me - I take it this is just a different method of specifying the maximum value?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month