Skip to content

Instantly share code, notes, and snippets.

@jimfleming
Created April 17, 2017 03:23
Show Gist options
  • Save jimfleming/8529219b05b797366bf823476efbf07f to your computer and use it in GitHub Desktop.
Save jimfleming/8529219b05b797366bf823476efbf07f to your computer and use it in GitHub Desktop.
Return random integers from low (inclusive) to high (exclusive). Interface borrowed from numpy.random.randint.
def randint(low, high=None, size=None, dtype=tf.int32):
"""
Return random integers from low (inclusive) to high (exclusive).
Interface borrowed from numpy.random.randint.
"""
if high is None:
high = low
low = 0
assert dtype.is_integer(), 'dtype for randint must be an integer'
return tf.random_uniform(shape=size, minval=low, maxval=high, dtype=dtype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment