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. Quote 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. Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/46578-solved-rand-function/#findComment-226731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.