lundi 29 juin 2020

Using Random_int instead of Rand()

I am currently using Rand() to select a random result from a table using a simple Rand() and where SQL query.

Existing code:

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'];

I would like to change this to use Random_int instead as this provide more genuine randomness which is needed for the application.

I have tried this but it is not working:

  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);
    }

Please can someone help to correct the above code.




Aucun commentaire:

Enregistrer un commentaire