note 98195 added to function.rand
liveonaware
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
<?php
//To Pull 7 Unique Random Values Out Of AlphaNumeric
//removed number 0, capital o, number 1 and small L
//Total: keys = 32, elements = 33
$characters = array(
"A","B","C","D","E","F","G","H","J","K","L","M",
"N","P","Q","R","S","T","U","V","W","X","Y","Z",
"1","2","3","4","5","6","7","8","9");
//make an "empty container" or array for our keys
$keys = array();
//first count of $keys is empty so "1", remaining count is 1-6 = total 7 times
while(count($keys) < 7) {
//"0" because we use this to FIND ARRAY KEYS which has a 0 value
//"-1" because were only concerned of number of keys which is 32 not 33
//count($characters) = 33
$x = mt_rand(0, count($characters)-1);
if(!in_array($x, $keys)) {
$keys[] = $x;
}
}
foreach($keys as $key){
$random_chars .= $characters[$key];
}
echo $random_chars;
?>
----
Server IP: 69.147.83.197
Probable Submitter: 114.108.194.168
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/98195
Del: integrated -- https://master.php.net/note/delete/98195/integrated
Del: useless -- https://master.php.net/note/delete/98195/useless
Del: bad code -- https://master.php.net/note/delete/98195/bad+code
Del: spam -- https://master.php.net/note/delete/98195/spam
Del: non-english -- https://master.php.net/note/delete/98195/non-english
Del: in docs -- https://master.php.net/note/delete/98195/in+docs
Del: other reasons-- https://master.php.net/note/delete/98195
Reject -- https://master.php.net/note/reject/98195
Search -- https://master.php.net/manage/user-notes.php