In yii i am creating random number generating function. I am using function as-
public function randomNumber()
{
//for generating random number
$length =3;
$chars = array_merge(range(0,9));
shuffle($chars);
$password = implode(array_slice($chars, 0,$length));
echo $password;
}
but in above function its creating random number as per length specified. i.e. if length is defined as 2, then it will create 2 digit number,if 3 then 3 digit number and so on. Now my condition is i want to generate random number between 1 to 1000. It can be 1 digit, 2 digit or 3 digit. So how to modify this function? Or is there any other way? Please help me...
you can use this function:
Yii::app()->getSecurityManager()->generateRandomString($length);
Documentation of this function can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With