"""Helpers for monosort.dc.

Loaded via:  ./pydc dcsrc/monosort.dc dcsrc/monosort_lib.py

`randints(N)` returns 2^N random integers in [0, 99] — small enough that
the trace stays readable, big enough that collisions are rare for small N.

`shuffled(N)` returns a uniform permutation of [0..2^N - 1] — useful for
verifying the sort end-to-end (output should be [0, 1, ..., 2^N - 1])."""

import random


def randints(N, lo=0, hi=99, seed=None):
    """List of 2**N random integers in [lo, hi]."""
    if seed is not None:
        random.seed(seed)
    return [random.randint(lo, hi) for _ in range(2 ** N)]


def shuffled(N, seed=None):
    """A random permutation of [0..2**N - 1]."""
    if seed is not None:
        random.seed(seed)
    arr = list(range(2 ** N))
    random.shuffle(arr)
    return arr
