Re: Sequential Random Character Generator
| From: | Adam Bregenzer | Date: | Wed, 25 Feb 2004 16:41:43 +0000 |
| Subject: | Re: Sequential Random Character Generator | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178852@lists.php.net to get a copy of this message | ||
On Wed, 2004-02-25 at 11:25, list@pfohlsolutions.com wrote:
> I'm trying to create a PHP sequential random character generator that will output to a
> file database of some sort. The randomization needs to be using both capital letters and numbers. I
> need to output like 2 million records. Can someone point me in the right direction on how to do
> this?
>
> I'm also looking to to this without letters as well.
Make an array containing the characters/numbers/whatever you want to be
selected at random then pick from it using a random integer generated
from mt_rand[1] and echo your selection. If you have PHP < 4.2.0 you
will also need to use mt_srand[2].
$field = array('a','b');
$field_max = count($field) - 1;
echo $field[mt_rand(0, $field_max)];
[1] http://www.php.net/mt_rand
[2] http://www.php.net/mt_srand
--
Adam Bregenzer
adam@bregenzer.net