zmpi8q
Last Updated: February 25, 2016
·
930
· dlion
28864ba1e7e4490c3e5e97e095d4b6c7

Generate random alphanumerics strings with random.org

To generate random alphanumerics you can youse random.org services in your php code.

<?php
function random($num,$len)
{   
    if($len >= 1 && $len <= 20)
    {   
        $random = file_get_contents("http://www.random.org/strings/?num=$num&len=$len&digits=on&upperalpha=on&loweralpha=on&unique=on&format=plain&rnd=new");

        $result = array();
        $data = explode("\n",$random);
        for($i=0; $i < $num; $i++)
            $result[$i] = $data[$i];
    }
    else
        return -1;

    return $result;
}
?>

This function return an array with num strings

You can do it:

<?php
$list = array();

$list = random(10,10);

for($i=0; $i < 10; $i++)
    echo $list[$i]."</br>";
?>

Obviously it's only an example!
If in your server is enable getfilecontent function why you don't use it ?
It's simple, fast and secure.

I have omitted a function to check that random.org sites is online but it is not hard to write it ;)

Say Thanks
Respond