# tf.random.experimental.set_global_generator

<br />

|---|
| [![](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/stateful_random_ops.py#L689-L708) |

Replaces the global generator with another `Generator` object.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.random.experimental.set_global_generator`](https://www.tensorflow.org/api_docs/python/tf/random/set_global_generator), \`tf.compat.v2.random.experimental.set_global_generator\`

<br />

    tf.random.experimental.set_global_generator(
        generator
    )

This function creates a new Generator object (and the Variable object within),
which does not work well with tf.function because (1) tf.function puts
restrictions on Variable creation thus reset_global_generator can't be freely
used inside tf.function; (2) redirecting a global variable to
a new object is problematic with tf.function because the old object may be
captured by a 'tf.function'ed function and still be used by it.
A 'tf.function'ed function only keeps weak references to variables,
so deleting a variable and then calling that function again may raise an
error, as demonstrated by
random_test.py/RandomTest.testResetGlobalGeneratorBadWithDefun .

<br />

<br />

<br />

| ## Args ||
|---|---|
| `generator` | the new `Generator` object. |

<br />