Quantcast
Channel: technology –クオリアシステムズ ブログ
Viewing all articles
Browse latest Browse all 41

PHP:6桁の乱数を取得するには

$
0
0

6桁の乱数をとるには、ランダム関数を使用します。

ランダム関数は主に二つ存在します。

「rand」と「mt_rand」です。

どちらも乱数をとることができますが、「rand」より「mt_rand」のほうが4倍処理がはやいので「mt_rand」を使用することが推奨されているようです。

なので「mt_rand」を使用することにします。


$str="";
for($i=0;$i<6;$i++){
    $str.=mt_rand(0,9);
}

これで、6桁の乱数を取得することができます。

 

 


Viewing all articles
Browse latest Browse all 41

Trending Articles