# randint_like¶

paddle. randint_like ( x, low=0, high=None, dtype=None, name=None ) [source]

Returns a Tensor filled with random integers from a discrete uniform distribution in the range [`low`, `high`), with the same shape as `x`. (use `dtype` if `dtype` is not None) If `high` is None (the default), the range is [0, `low`).

Parameters
• x (Tensor) – The input multi-dimensional tensor which specifies shape. The dtype of `x` can be bool, int32, int64, float16, float32, float64.

• low (int, optional) – The lower bound on the range of random values to generate. The `low` is included in the range. If `high` is None, the range is [0, `low`). Default is 0.

• high (int, optional) – The upper bound on the range of random values to generate, the `high` is excluded in the range. Default is None. If `high` is None, the range is [0, `low`).

• dtype (str|np.dtype, optional) – The data type of the output tensor. Supported data types: bool, int32, int64, float16, float32, float64. If `dtype` is None, the data type is the same as x’s data type. Default is None.

• name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

A Tensor filled with random integers from a discrete uniform distribution in the range [`low`, `high`), with `shape` and `dtype`.

Return type

Tensor

Examples

```>>> import paddle

>>> # example 1:
>>> # dtype is None and the dtype of x is float32
>>> out2 = paddle.randint_like(x, low=-5, high=5)
>>> print(out2)
>>>
[[0., 0.]])
>>>
>>> print(out2.dtype)

>>> # example 2:
>>> # dtype is None and the dtype of x is float64
>>> out2 = paddle.randint_like(x, low=-5, high=5)
>>> print(out2)
>>>
[[ 4., -5.]])
>>>
>>> print(out2.dtype)

>>> # example 3:
>>> # dtype is None and the dtype of x is int32
>>> out3 = paddle.randint_like(x, low=-5, high=5)
>>> print(out3)
>>>
[[ 0, -4]])
>>>
>>> print(out3.dtype)

>>> # example 4:
>>> # dtype is None and the dtype of x is int64
>>> out4 = paddle.randint_like(x, low=-5, high=5)
>>> print(out4)
>>>
[[ 4, -3]])
>>>
>>> print(out4.dtype)

>>> # example 5:
>>> # dtype is float64 and the dtype of x is float32
>>> out5 = paddle.randint_like(x, low=-5, high=5, dtype="float64")
>>> print(out5)
>>>
[[3., 1.]])
>>>
>>> print(out5.dtype)

>>> # example 6:
>>> # dtype is bool and the dtype of x is float32
>>> out6 = paddle.randint_like(x, low=-5, high=5, dtype="bool")
>>> print(out6)
>>>
[[False, True ]])
>>>
>>> print(out6.dtype)

>>> # example 7:
>>> # dtype is int32 and the dtype of x is float32
>>> out7 = paddle.randint_like(x, low=-5, high=5, dtype="int32")
>>> print(out7)
>>>
[[-2, -2]])
>>>
>>> print(out7.dtype)

>>> # example 8:
>>> # dtype is int64 and the dtype of x is float32
>>> out8 = paddle.randint_like(x, low=-5, high=5, dtype="int64")
>>> print(out8)
>>>
[[-5,  4]])
>>>
>>> print(out8.dtype)