First you can get random numbers and using md5 or any other encryption.
now you can get 40 or 36 char string. The string contains small, capital letters
and numeric values.
Use sub string pre-defined function, get the values based on your requirement.
<?php
$username = substr( md5(rand(100, 1000), 6, 8);
?>
6 -> it is the starting index value.
8 -> Total number Charectors for seeking from stating index value.
This is simple way to generate random password, Hope use this one and generate
password with complicated.