日替わりランダム値
「○○ごとに結果が異なるランダム値を出す」メモまとめ。
基本的に、「○○ごと」というのを数値化してseed値にすればOK。
// 実行するごとに異なる値(seed初期化) srand(); print(rand(1,10)); // 1日ごとに異なる値(seedに現在の日付を設定) srand(strtotime(date("Y-m-d", time()))); print(rand(1,10)); // 1時間ごとに異なる値(seedに現在の日時を設定) srand(strtotime(date("Y-m-d H:00:00", time()))); print(rand(1,10)); // 1日ごと・ユーザごとに異なる値(seedに現在の日付とユーザIDを足した値を設定) srand(strtotime(date("Y-m-d", time())) + $id); print(rand(1,10));