ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilRandom Class Reference

Wrapper for generation of random numbers, strings, bytes. More...

+ Collaboration diagram for ilRandom:

Public Member Functions

 int (int $min=0, int $max=PHP_INT_MAX)
 

Private Member Functions

 logIfPossible (callable $c)
 

Detailed Description

Wrapper for generation of random numbers, strings, bytes.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 10 of file class.ilRandom.php.

Member Function Documentation

◆ int()

ilRandom::int ( int  $min = 0,
int  $max = PHP_INT_MAX 
)

Definition at line 21 of file class.ilRandom.php.

References Vendor\Package\$e, ilLogLevel\ERROR, ilLogger\error(), logIfPossible(), and ilLogger\logStack().

21  : 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  }
logStack(?int $a_level=null, string $a_message='')
logIfPossible(callable $c)
error(string $a_message)
+ Here is the call graph for this function:

◆ logIfPossible()

ilRandom::logIfPossible ( callable  $c)
private

Definition at line 12 of file class.ilRandom.php.

References $c, and $DIC.

Referenced by int().

12  : void
13  {
14  global $DIC;
15 
16  if (isset($DIC['ilLoggerFactory'])) {
17  $c($DIC->logger()->rnd());
18  }
19  }
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: