PY-93
Generate Values within Stated Bounds
Task
Write generate_values_within_bounds(rng, kind, shape, lower, upper).
The function receives one already-created NumPy Generator. It must use that
generator for exactly one request and return a new dictionary with exactly these
keys:
values, evidence
values is a new NumPy array with the requested shape. evidence is a new
dictionary with exactly these keys:
kind, shape, dtype, lower, upper, minimum, maximum
The two supported kind values define the complete generation rule:
- For
"uniform",lowerandupperare finite numbers withlower < upper. Generatefloat64values from the half-open interval[lower, upper). The lower bound is included and the upper bound is excluded. - For
"integers",lowerandupperare integers withlower < upper. Generateint64values from the half-open interval[lower, upper).
shape must be a non-empty tuple or list of positive integers. The returned
evidence["shape"] is a tuple, and evidence["dtype"] is the string form of
the returned array's dtype. Store the requested bounds in lower and upper.
Store the smallest and largest generated values in minimum and maximum as
ordinary Python numbers. The generated values must satisfy the stated bounds.
Do not create or seed another generator. Do not change shape, lower,
upper, or any other argument. A valid call advances the supplied generator
by the one request described above. Invalid arguments must raise ValueError
before requesting values.
Example
The exact values depend on the generator state. The shape, dtype, interval, and range evidence are the reusable result of the function.
An integer request uses the same interface but a different local rule:
Every value is an integer in {0, 1, 2, 3}. The value 4 is not allowed.
Your implementation
You may import NumPy as np. Do not print, create a generator, seed global
state, or ask for input.