Return random integers from low (inclusive) to high (exclusive).
Return random integers from the “discrete uniform” distribution of the specified dtype in the “half-open” interval [low, high). If high is null (the default), then results are from [0, low).
sciphp/numphp>=0.5
SciPhp\NdArray
Random::randint(
int
$low
,
int
$high
,
int|array
$size
)
$low
$high
This parameter is optional.
If provided, one above the largest (signed) integer to be drawn from the distribution.$size
This parameter is optional.
Output shape. If the given shape is, e.g., [m, n, k], then m * n * k samples are drawn. Default is null, in which case a single value is returned.int or a NdArray of ints size-shaped array of random integers from the appropriate distribution, or a single such random int if size not provided.
use SciPhp\NumPhp as np;
$x = np::random()->randint(6);
echo $x;
The above example will output:
3
use SciPhp\NumPhp as np;
$x = np::random()->randint(-5, 6);
echo $x;
The above example will output:
x -2
use SciPhp\NumPhp as np;
$x = np::random()->randint(-10, 11, 10);
echo $x;
The above example will output:
[ 1 5 -8 -3 -1 -6 6 4 -8 7 ]
use SciPhp\NumPhp as np;
$x = np::random()->randint(-10, 11, [4, 2]);
echo $x;
The above example will output:
[[-2 -2 ] [ 7 -3 ] [ 5 3 ] [-2 0 ]]
x is the random generated matrice, y a triangular 4x4 and z=x.y
use SciPhp\NumPhp as np;
$x = np::tri(4);
$y = np::random()->randint(-10, 11, [4, 4]);
$z = $x->dot($y);
echo "x\n$x\n", "y\n$y\n", "z=x.y\n$z\n";
The above example will output:
x [[1 0 0 0] [1 1 0 0] [1 1 1 0] [1 1 1 1]] y [[-5 -10 -10 7 ] [-10 9 -6 5 ] [ 0 8 -1 10 ] [-2 -8 7 9 ]] z=x.y [[-5 -10 -10 7 ] [-15 -1 -16 12 ] [-15 7 -17 22 ] [-17 -1 -10 31 ]]