jax.random.randint range must be valid
`random.randint` doesn't check that `minval` < `maxval`. If it's not, you get surprising results. For example,
`print(random.randint(random.PRNGKey(10003), (), 0, 0))`
yields -1234647498.

The best thing would be to throw an error message, but if that's not practical then it'd at least be nice to have the behavior be defined.
diff --git a/jax/random.py b/jax/random.py
index 8b00c9ca7..8b4af32d3 100644
--- a/jax/random.py
+++ b/jax/random.py
@@ -245,6 +245,10 @@ def randint(key, shape, minval, maxval, dtype=onp.int32):
   if nbits not in (32, 64):
     raise TypeError("randint only accepts 32- or 64-bit dtypes.")
 
+  # if we don't have minval < maxval, just always return minval
+  # https://github.com/google/jax/issues/222
+  maxval = lax.max(lax.add(minval, onp.array(1, dtype)), maxval)
+
   # This algorithm is biased whenever (maxval - minval) is not a power of 2.
   # We generate double the number of random bits required by the dtype so as to
   # reduce that bias.
diff --git a/tests/random_test.py b/tests/random_test.py
index 46963f076..9aada5a38 100644
--- a/tests/random_test.py
+++ b/tests/random_test.py
@@ -149,6 +149,10 @@ class LaxRandomTest(jtu.JaxTestCase):
     self.assertFalse(onp.all(perm1 == x))  # seems unlikely!
     self.assertTrue(onp.all(onp.sort(perm1) == x))
 
+  def testIssue222(self):
+    x = random.randint(random.PRNGKey(10003), (), 0, 0)
+    assert x == 0
+
 
 if __name__ == "__main__":
   absltest.main()
['jax/random.py', 'tests/random_test.py']