施義
Lv 5
施義 發問時間: 電腦與網際網路程式設計 · 1 0 年前

一個簡單php問題

請問

如何用php寫出

產生亂數的網頁?

例如 產生0~10其中一個數

然後在網頁中顯示

2 個解答

評分
  • Jelly
    Lv 7
    1 0 年前
    最佳解答

    http://tw.php.net/manual/en/function.rand.php

    int rand ([ int $min ], int $max )

    If called without the optional min , max arguments rand() returns a pseudo-random integer between 0 and RAND_MAX. If you want a random number between 5 and 15 (inclusive), for example, use rand (5, 15).

    Note: On some platforms (such as Windows) RAND_MAX is only 32768. If you require a range larger than 32768, specifying min and max will allow you to create a range larger than RAND_MAX, or consider using mt_rand() instead.

    Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.

    echo rand(0,10);

    參考資料: 我亂掰的 聽聽就好
  • 4 年前

    <body>

    <?php

    $a=rand(0,10);

    echo $a;

    ?>

    </body>

    </html>

    參考資料: 今天上課老師教的in台中職訓局
還有問題?馬上發問,尋求解答。