Diff for phpPlatonLib/common/rand/Attic/fnc.rand_str.php between version 1.1 and 1.2
| version 1.1, 2002/04/20 10:00:43 |
version 1.2, 2002/04/21 23:21:20 |
|
|
| <?php |
<?php |
| |
|
| /** |
/* |
| * Returns a random string of length $len consisting of A-Z 0-9. |
* phpPlatonLib - Platon software development group PHP library |
| * The first character will always be an alphabet. |
|
| * |
* |
| * Requires srand() |
* common/rand/fnc.rand_str.php - return random string of length |
| |
* $len consisting of A-Z and 0-9; first character will always be |
| |
* an alphabet; require srand() |
| |
* ____________________________________________________________ |
| |
* |
| |
* Developed by Ondrej Jombik <nepto@pobox.sk> |
| |
* Copyright (c) 2001-2002 Platon SDG, http://www.platon.sk/ |
| |
* All rights reserved. |
| |
* |
| |
* See README file for more information about this software. |
| |
* See COPYING file for license information. |
| |
* |
| |
* Download the latest version from |
| |
* http://www.platon.sk/projects/phpPlatonLib/ |
| */ |
*/ |
| |
|
| function rand_str($len = 8) |
/* $Id$ */ |
| { |
|
| $s = ''; |
if (! defined('phpPlatonLib_fnc_rand_str')) { |
| |
define('phpPlatonLib_fnc_rand_str', 1); |
| for ($i = 0; $i < $len; $i++) { |
|
| if ($i == 0) |
function rand_str($len = 8) |
| $r = rand() % 26; |
{ |
| else |
$s = ''; |
| $r = rand() % 36; |
|
| |
for ($i = 0; $i < $len; $i++) { |
| if ($r >= 26) |
if ($i == 0) |
| $s .= chr($r + ord('0') - 26); |
$r = rand() % 26; |
| else |
else |
| $s.= chr($r + ord('A')); |
$r = rand() % 36; |
| |
|
| |
if ($r >= 26) |
| |
$s .= chr($r + ord('0') - 26); |
| |
else |
| |
$s.= chr($r + ord('A')); |
| |
} |
| |
|
| |
return $s; |
| } |
} |
| |
|
| return $s; |
|
| } |
} |
| |
|
| ?> |
?> |
Platon Group <platon@platon.org> http://platon.org/
|
|