# tf.random.categorical

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/random/categorical) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/random_ops.py#L364-L389) |

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), \`tf.compat.v2.random.categorical\`

<br />

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

#### 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` | integer type to use for the output. Defaults to int64. |
| `seed` | A Python integer. Used to create a random seed for the distribution. See [`tf.compat.v1.set_random_seed`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/random/set_random_seed) for behavior. |
| `name` | Optional name for the operation. |

<br />

<br />

<br />

<br />

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

<br />