PHP 中的 srand() 函式


mt_srand() 函式為隨機數生成器設定種子。

注意 − 隨機數生成器在 PHP 4.2.0 釋出後自動設定種子。此函式現在不需要了。

語法

srand(seed)

引數

  • 種子 − 種子值

返回

srand() 函式不返回任何物件。

例項

 例項演示

<?php
   srand(mktime());
   echo(mt_rand());
?>

輸出

664617053

例項

我們來看另一個例項 −

 例項演示

<?php
   srand(2);
   echo(rand(1, 5));
?>

輸出

4

更新時間: 2019 年 12 月 27 日

164 次瀏覽

開創你的 職業道路

完成課程認證

開始行動
廣告
© . All rights reserved.