Jump to content

Random Code Generator


ansipants

Recommended Posts

Ok, so I'm attempting to work on a script that will generate random codes and I also want to be able to change the multiplier with a form. Here is what I have so far:

 

<code>

 

 

<?php

$chars = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Alpha numberic character

$chars .= "123456789";

$chars .= "123456789";

$chars .= "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

$chars .= "123456789";

$chars .= "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

$chars .= "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

$chars .= "123456789";

$chars .= "123456789";

$chars = str_shuffle($chars);

$chars = substr($chars, 0, 15);

 

/** This is the part I'm not sure how to do because

it generates the same codes 5 times in a row and I want

it to generate different codes on each line or maybe do a form that

I can change the multiplier number to generate more

*/

 

$input = $chars;

$multiplier = 5;

$separator = "<br>\n";

print implode($separator, array_fill(0, $multiplier, $input));

print "<br>\n";

 

?>

</code>

 

Sorry I'm a n00b and trying to learn more =)

Link to comment
https://forums.phpfreaks.com/topic/270443-random-code-generator/
Share on other sites

<?php

$letters    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Alpha characters
$numbers    = "123456789"; //Numeric characters
$characters = str_repeat($letters, 4) . str_repeat($numbers, 9);

$multiplier = 5;
$length = 15;
$separator = "<br>\n";

$codes = array();
for($i=0; $i<$multiplier; $i++)
{
   $rand_chars = str_shuffle($characters);
   $codes[] = substr($rand_chars, 0, $length);
}

print implode($separator, $codes);
print "<br>\n";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.