Tensorflow random.uniform() does not give uniform output

131 Views Asked by At

I am trying to test if the tensorflow's random.uniform() function gives a nearly uniform output using the following snippet:

value_count = {1: 0,
               2: 0,
               3: 0,
               4: 0,
               5: 0}


import matplotlib.pyplot as plt
import numpy as np


for i in range(0, 10000):
    random_1 = tf.random.uniform(shape=(1,), minval=1, maxval=6, dtype=tf.int32)
    value_count[int(random_1[0])] = value_count[int(random_1[0])] + 1

keys, values = zip(*value_count.items())
print(keys)

plt.plot(keys, values)
plt.show()

The expected output for me was a line nearly parallel to X-axis. But I got the following:

Run 1:

enter image description here

Run 2:

enter image description here

I never got a nearly straight line parallel to X-axis.

Am I doing something wrong or have I misunderstood how the function works?

0

There are 0 best solutions below