maxic0 Posted April 11, 2007 Share Posted April 11, 2007 I was looking up and learning about functions, and i was given this example to create a random password. <?php function rand_pass() { $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz"; $thepass = ''; for($i=0;$i<10;$i++) { $thepass .= $chars{rand() % 39}; } return $thepass; } $password= rand_pass(); echo $password; ?> I understand it all apart from the $thepass .= $chars{rand() % 39}; What does the "% 39" bit mean? Thanks. Link to comment https://forums.phpfreaks.com/topic/46578-solved-rand-function/ Share on other sites More sharing options...
wildteen88 Posted April 11, 2007 Share Posted April 11, 2007 it selects a character from the 39 characters in the $chars variable also % is the modulos operator. it returns the remainder from a division sum. Link to comment https://forums.phpfreaks.com/topic/46578-solved-rand-function/#findComment-226730 Share on other sites More sharing options...
maxic0 Posted April 11, 2007 Author Share Posted April 11, 2007 Ok, thanks wildteen88 Link to comment https://forums.phpfreaks.com/topic/46578-solved-rand-function/#findComment-226731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.