homepage Welcome to WebmasterWorld Guest from 50.17.107.233
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved