ILIAS  release_8 Revision v8.24
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
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 {
28 $logger->error('No suitable random number generator found.');
29 });
30 throw $e;
31 }
32 }
33}
Component logger with individual log levels by component id.
error(string $a_message)
logStack(?int $a_level=null, string $a_message='')
Wrapper for generation of random numbers, strings, bytes.
int(int $min=0, int $max=PHP_INT_MAX)
logIfPossible(callable $c)
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28