# randint_like¶

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

## 参数¶

• x (Tensor) – 输入的多维 Tensor，数据类型可以是 bool，int32，int64，float16，float32，float64。输出 Tensor 的形状和 `x` 相同。如果 `dtype` 为 None，则输出 Tensor 的数据类型与 `x` 相同。

• low (int，可选) - 要生成的随机值范围的下限，`low` 包含在范围中。当 `high` 为 None 时，均匀采样的区间为[0, `low`)。默认值为 0。

• high (int，可选) - 要生成的随机值范围的上限，`high` 不包含在范围中。默认值为 None，此时范围是[0, `low`)。

• dtype (str|np.dtype，可选) - 输出 Tensor 的数据类型，支持 bool，int32，int64，float16，float32，float64。当该参数值为 None 时，输出 Tensor 的数据类型与输入 Tensor 的数据类型一致。默认值为 None。

• name (str，可选) - 具体用法请参见 Name，一般无需设置，默认值为 None。

## 返回¶

Tensor：从区间[`low``high`)内均匀分布采样的随机 Tensor，形状为 `x.shape`，数据类型为 `dtype`

## 代码示例¶

```>>> 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)