Home > Backend Development > PHP Tutorial > PHP generates random numbers with custom function randstr($length)

PHP generates random numbers with custom function randstr($length)

巴扎黑
Release: 2016-11-23 11:51:17
Original
2616 people have browsed it

function randstr($len=6){ 
    $chars='abcdefghijklmnopqrstuvwxyz0123456789'; 
    #characters to build the password from 
    mt_srand((double)microtime()*1000000*getmypid()); 
    #seed the random number generater (must be done) 
    $password=''; 
    while(strlen($password)<$len) 
        $password.=substr($chars,(mt_rand()%strlen($chars)),1); 
    return $password; 


$salt = randstr();

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template