[英]Change from MySQL Rand() to PHP random_int
我們正在創建一個隨機數游戲。 我們目前在以下語句中使用 MySQL Rand() 函數:
private function doPreEventStart($user) {
$row = db_fetch_item("SELECT resultid FROM ResultPackage
where ResultPackage.slotid like '%{$this->curSlotId}'
and ResultPackage.PackageID like '%{$user->packageid}%'
ORDER BY RAND() LIMIT 1");
$this->curResultId = $row['resultid'];
}
我們需要將其更改為 PHP 函數 Random_Int。 請有人通過更改上述代碼來建議一種方法。 從SQL語句中的WHERE條件可以看出,隨機數仍然需要在一定范圍內。
我正在測試此代碼:
private function doPreEventStart($user) {
$row = db_fetch_item("SELECT resultid as MaxResult FROM ResultPackage
where ResultPackage.slotid like '%{$this->curSlotId}'
and ResultPackage.PackageID like '%{$user->packageid}%'
ORDER BY resultid desc LIMIT 1");
$this->MaxResult = $row['MaxResult'];
$row = db_fetch_item("SELECT resultid as MinResult FROM ResultPackage
where ResultPackage.slotid like '%{$this->curSlotId}'
and ResultPackage.PackageID like '%{$user->packageid}%'
ORDER BY resultid asc LIMIT 1");
$this->MinResult = $row['MinResult'];
$this->curResultId = int rand ( int $MinResult , int $MaxResult )
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.