# tf.random.stateless_categorical

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/ops/stateless_random_ops.py#L793-L832) |

Draws deterministic pseudorandom samples from a categorical distribution.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.random.stateless_categorical`](https://www.tensorflow.org/api_docs/python/tf/random/stateless_categorical)

<br />

    tf.random.stateless_categorical(
        logits,
        num_samples,
        seed,
        dtype=https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/dtypes#int64,
        name=None
    )

This is a stateless version of `tf.categorical`: 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.

#### Example:

    # samples has shape [1, 5], where each value is either 0 or 1 with equal
    # probability.
    samples = tf.random.stateless_categorical(
        tf.math.log([[0.5, 0.5]]), 5, seed=[7, 17])

<br />

<br />

<br />

| ## Args ||
|---|---|
| `logits` | 2-D Tensor with shape `[batch_size, num_classes]`. Each slice `[i, :]` represents the unnormalized log-probabilities for all classes. |
| `num_samples` | 0-D. Number of independent samples to draw for each row slice. |
| `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.) |
| `dtype` | The integer type of the output: `int32` or `int64`. Defaults to `int64`. |
| `name` | Optional name for the operation. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| The drawn samples of shape `[batch_size, num_samples]`. ||

<br />