Skip to content

Latest commit

 

History

History
55 lines (33 loc) · 1.21 KB

File metadata and controls

55 lines (33 loc) · 1.21 KB

PseudoRandom

Introduction

The PseudoRandom component is a component that generates pseudo-random numbers.

?> The PseudoRandom component is meant as a direct replacement for PHP mt_rand(), rand() functions.

Usage

use Psl\PseudoRandom;

$random_number = PseudoRandom\int();
$random_float = PseudoRandom\float();

API

Functions

  • [@external-mutation-free php]
    [PseudoRandom\int(int $min = Math\INT64_MIN, int $max = Math\INT64_MAX): int php]

    Returns a pseudo-random integer in the given range.

    • [$min php]: The minimum value.
    • [$max php]: The maximum value.

    If [$min php] is greater than [$max php], [Psl\Exception\InvariantViolationException php] is thrown.

    use Psl\PseudoRandom;
    
    $random_number = PseudoRandom\int(0, 10);
    
    // 0 <= $random_number <= 10
  • [@external-mutation-free php]
    [PseudoRandom\float(): float php]

    Returns a pseudo-random float in the range of [0.0, 1.0].

    use Psl\PseudoRandom;
    
    $random_float = PseudoRandom\float();
    
    // 0.0 <= $random_float <= 1.0