Complete worked example
python
import numpy as np
def inspect_example(identifiers, count, seed):
ids = np.asarray(identifiers, dtype=np.int64)
if ids.ndim != 1 or np.unique(ids).size != ids.size:
raise ValueError("expected unique identifiers")
if type(count) is not int or not 0 <= count <= ids.size:
raise ValueError("sample size exceeds the population")
rng = np.random.default_rng(seed)
result = rng.choice(ids, size=count, replace=False)
return result- Reasoning
- The worked function constructs default_rng(seed) and calls choice on an explicit int64 identifier array with replace=False. Equal identifiers are rejected before sampling because sampling distinct positions from duplicated values would not establish unique canonical results. A request for more identifiers than exist is rejected rather than silently returning a partial sample. The lab checks sample values under its pinned environment, exact dtype and shape, uniqueness and unchanged caller input. It also checks that the legacy global NumPy random state does not change. This makes ownership observable rather than inferring it from whether the result looks random.