ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilRandom.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
10 class ilRandom
11 {
12  private function logIfPossible(callable $c): void
13  {
14  global $DIC;
15 
16  if (isset($DIC['ilLoggerFactory'])) {
17  $c($DIC->logger()->rnd());
18  }
19  }
20 
21  public function int(int $min = 0, int $max = PHP_INT_MAX): int
22  {
23  try {
24  return random_int($min, $max);
25  } catch (Throwable $e) {
26  $this->logIfPossible(static function (ilLogger $logger): void {
27  $logger->logStack(ilLogLevel::ERROR);
28  $logger->error('No suitable random number generator found.');
29  });
30  throw $e;
31  }
32  }
33 }
logStack(?int $level=null, string $message='', array $context=[])
$c
Definition: deliver.php:9
logIfPossible(callable $c)
global $DIC
Definition: shib_login.php:25
int(int $min=0, int $max=PHP_INT_MAX)
Wrapper for generation of random numbers, strings, bytes.
error(string $message, array $context=[])