tf.random.stateless_uniform
Stay organized with collections
Save and categorize content based on your preferences.
Outputs deterministic pseudorandom values from a uniform distribution.
tf.random.stateless_uniform(
shape,
seed,
minval=0,
maxval=None,
dtype=tf.dtypes.float32
,
name=None,
alg='auto_select'
)
Used in the notebooks
This is a stateless version of tf.random.uniform
: if run twice with the
same seeds and shapes, it will produce the same pseudorandom numbers. The
output is consistent across multiple runs on the same hardware (and between
CPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU
hardware.
The generated values follow a uniform distribution in the range
[minval, maxval)
. The lower bound minval
is included in the range, while
the upper bound maxval
is excluded.
For floats, the default range is [0, 1)
. For ints, at least maxval
must
be specified explicitly.
In the integer case, the random integers are slightly biased unless
maxval - minval
is an exact power of two. The bias is small for values of
maxval - minval
significantly smaller than the range of the output (either
2**32
or 2**64
).
For full-range (i.e. inclusive of both max and min) random integers, pass
minval=None
and maxval=None
with an integer dtype
. For an integer dtype
either both minval
and maxval
must be None
or neither may be None
. For
example:
ints = tf.random.stateless_uniform(
[10], seed=(2, 3), minval=None, maxval=None, dtype=tf.int32)
Args |
shape
|
A 1-D integer Tensor or Python array. The shape of the output tensor.
|
seed
|
A shape [2] Tensor, the seed to the random number generator. Must have
dtype int32 or int64 . (When using XLA, only int32 is allowed.)
|
minval
|
A Tensor or Python value of type dtype , broadcastable with shape
(for integer types, broadcasting is not supported, so it needs to be a
scalar). The lower bound on the range of random values to generate. Pass
None for full-range integers. Defaults to 0.
|
maxval
|
A Tensor or Python value of type dtype , broadcastable with shape
(for integer types, broadcasting is not supported, so it needs to be a
scalar). The upper bound on the range of random values to generate.
Defaults to 1 if dtype is floating point. Pass None for full-range
integers.
|
dtype
|
The type of the output: float16 , bfloat16 , float32 , float64 ,
int32 , or int64 . For unbounded uniform ints (minval , maxval both
None ), uint32 and uint64 may be used. Defaults to float32 .
|
name
|
A name for the operation (optional).
|
alg
|
The RNG algorithm used to generate the random numbers. Valid choices
are "philox" for the Philox
algorithm,
"threefry" for the ThreeFry
algorithm,
and "auto_select" (default) for the system to automatically select an
algorithm based the device type. Values of tf.random.Algorithm can also
be used. Note that with "auto_select" , the outputs of this function may
change when it is running on a different device.
|
Returns |
A tensor of the specified shape filled with random uniform values.
|
Raises |
ValueError
|
If dtype is integral and only one of minval or maxval is
specified.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.random.stateless_uniform\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/stateless_random_ops.py#L274-L408) |\n\nOutputs deterministic pseudorandom values from a uniform distribution.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.random.stateless_uniform`](https://www.tensorflow.org/api_docs/python/tf/random/stateless_uniform)\n\n\u003cbr /\u003e\n\n tf.random.stateless_uniform(\n shape,\n seed,\n minval=0,\n maxval=None,\n dtype=../../tf/dtypes#float32,\n name=None,\n alg='auto_select'\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Substantial Undocumented Infection Facilitates the Rapid Dissemination of Novel Coronavirus (SARS-CoV2)](https://www.tensorflow.org/probability/examples/Undocumented_Infection_and_the_Dissemination_of_SARS-CoV2) - [TFP Release Notes notebook (0.11.0)](https://www.tensorflow.org/probability/examples/TFP_Release_Notebook_0_11_0) |\n\nThis is a stateless version of [`tf.random.uniform`](../../tf/random/uniform): if run twice with the\nsame seeds and shapes, it will produce the same pseudorandom numbers. The\noutput is consistent across multiple runs on the same hardware (and between\nCPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU\nhardware.\n\nThe generated values follow a uniform distribution in the range\n`[minval, maxval)`. The lower bound `minval` is included in the range, while\nthe upper bound `maxval` is excluded.\n\nFor floats, the default range is `[0, 1)`. For ints, at least `maxval` must\nbe specified explicitly.\n\nIn the integer case, the random integers are slightly biased unless\n`maxval - minval` is an exact power of two. The bias is small for values of\n`maxval - minval` significantly smaller than the range of the output (either\n`2**32` or `2**64`).\n\nFor full-range (i.e. inclusive of both max and min) random integers, pass\n`minval=None` and `maxval=None` with an integer `dtype`. For an integer dtype\neither both `minval` and `maxval` must be `None` or neither may be `None`. For\nexample: \n\n ints = tf.random.stateless_uniform(\n [10], seed=(2, 3), minval=None, maxval=None, dtype=tf.int32)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `shape` | A 1-D integer Tensor or Python array. The shape of the output tensor. |\n| `seed` | A shape \\[2\\] Tensor, the seed to the random number generator. Must have dtype `int32` or `int64`. (When using XLA, only `int32` is allowed.) |\n| `minval` | A Tensor or Python value of type `dtype`, broadcastable with `shape` (for integer types, broadcasting is not supported, so it needs to be a scalar). The lower bound on the range of random values to generate. Pass `None` for full-range integers. Defaults to 0. |\n| `maxval` | A Tensor or Python value of type `dtype`, broadcastable with `shape` (for integer types, broadcasting is not supported, so it needs to be a scalar). The upper bound on the range of random values to generate. Defaults to 1 if `dtype` is floating point. Pass `None` for full-range integers. |\n| `dtype` | The type of the output: `float16`, `bfloat16`, `float32`, `float64`, `int32`, or `int64`. For unbounded uniform ints (`minval`, `maxval` both `None`), `uint32` and `uint64` may be used. Defaults to `float32`. |\n| `name` | A name for the operation (optional). |\n| `alg` | The RNG algorithm used to generate the random numbers. Valid choices are `\"philox\"` for [the Philox algorithm](https://www.thesalmons.org/john/random123/papers/random123sc11.pdf), `\"threefry\"` for [the ThreeFry algorithm](https://www.thesalmons.org/john/random123/papers/random123sc11.pdf), and `\"auto_select\"` (default) for the system to automatically select an algorithm based the device type. Values of [`tf.random.Algorithm`](../../tf/random/Algorithm) can also be used. Note that with `\"auto_select\"`, the outputs of this function may change when it is running on a different device. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tensor of the specified shape filled with random uniform values. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|---------------------------------------------------------------------------|\n| `ValueError` | If `dtype` is integral and only one of `minval` or `maxval` is specified. |\n\n\u003cbr /\u003e"]]