【发布时间】:2020-06-29 09:42:06
【问题描述】:
我目前正在使用 Rand() 使用简单的 Rand() 和 where SQL 查询从表中选择随机结果。
现有代码:
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'];
我想将其更改为使用 Random_int,因为这提供了应用程序所需的更真实的随机性。
我试过了,但还是不行:
private function doPreEventStart($user) {
$row = db_fetch_item("SELECT resultid FROM ResultPackage
where ResultPackage.slotid like ‘%{$slot_id}'
and ResultPackage.PackageID like '%{$user->packageid}%'
ORDER BY resultid asc LIMIT 1");
$this->MinResult = $row['resultid'];
var_dump(random_int($this->MinResult,$this->MaxResult) + ", SLOTID=" + $slot_id);
}
请有人帮忙更正上面的代码。
【问题讨论】:
-
我对你想要达到的目标有点困惑。在代码中,您从数据库中选择 1 行,然后在 1 行 resultid 列和...之间生成一个随机数……什么?您何时以及在 $this->MaxResult 中声明什么?
-
是什么不工作?你有错误信息吗?