<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/random_ops.py#L394-L421) |

Draws 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.categorical`](https://www.tensorflow.org/api_docs/python/tf/random/categorical)

<br />

    tf.random.categorical(
        logits, num_samples, dtype=None, seed=None, name=None
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Generate music with an RNN](https://www.tensorflow.org/tutorials/audio/music_generation) - [Playing CartPole with the Actor-Critic method](https://www.tensorflow.org/tutorials/reinforcement_learning/actor_critic) - [Text generation with an RNN](https://www.tensorflow.org/text/tutorials/text_generation) - [Wiki40B Language Models](https://www.tensorflow.org/hub/tutorials/wiki40b_lm) - [Federated Learning for Text Generation](https://www.tensorflow.org/federated/tutorials/federated_learning_for_text_generation) |

#### Example:

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

<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. |
| `dtype` | The integer type of the output: `int32` or `int64`. Defaults to `int64`. |
| `seed` | A Python integer. Used to create a random seed for the distribution. See [`tf.random.set_seed`](https://www.tensorflow.org/api_docs/python/tf/random/set_seed) for behavior. |
| `name` | Optional name for the operation. |

<br />

<br />

<br />

<br />

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

<br />