Detects if a random seed is set before random number generation. Setting a seed is important for improving reproducibility and avoiding non-determinism.
1def tensorflow_control_sources_of_randomness_noncompliant():
2 import tensorflow as tf
3 # Noncompliant: seed is not set.
4 print(tf.random.uniform([1]))
1def tensorflow_control_sources_of_randomness_compliant(seed):
2 import tensorflow as tf
3 # Compliant: sets the seed.
4 tf.random.set_seed(seed)
5 print(tf.random.uniform([1]))