note 76886 deleted from function.rand by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: mno2go at gmail dot com 

----

Perhaps not the most efficient way, but one that is quite simple and provides for easy control over characters used in the generated strings/passwords:

<?php
	function generateCode($length=6) {
		$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789";
		$code = "";
		while (strlen($code) < $length) {
			$code .= $chars[mt_rand(0,strlen($chars))];
		}
		return $code;
	}
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.