Oops, obviously I meant:

def plusone(i: int[1:1_000_000_000]):
    return i+1

random.seed(42)
for n in range(1_000_000):
      plusone(random.randint(1, 1_000_000_001))

Or a zillion other things. I can construct orbitals of Mandelbrot set that may or may not be bounded. Or bounds that depend on the twin prime conjecture. Or whatever. Mersenne Twister is just a non-obvious calculation that we have convenient functions for.

On Sat, Aug 8, 2020, 1:28 AM David Mertz <mertz@gnosis.cx> wrote:


On Sat, Aug 8, 2020, 1:12 AM Steven D'Aprano 
Static languages often check what
bounds they can at compile time, and optionally insert bound checking runtime code for ambiguous places.

Yep. That's an assert, or it's moral equivalent.

Here's a deterministic program using the hypothetical new feature.

def plusone(i: int[1:1_000_000_000]):
    return i+1

random.seed(42)
for n in range(1_000_000):
      random.randint(1, 1_000_000_001)

Is this program type safe? Tell me by static analysis of Mersenne Twister.

Or if you want to special case the arguments to randint, will, lots of things. Let's say a "random" walk on the integer number line where each time through the loop increments or decrements some (deterministic but hard to calculate) amount. After N steps are we within certain bounds?