v9.1.1
Menu

Random Arrays

easyFREEArray Creation & BasicsNumPy RandomNumPy Foundations

Problem Statement

Generate random arrays with specific properties.

Background

NumPy's random module provides:

  • np.random.seed(n) - for reproducibility
  • np.random.rand(m, n) - uniform [0, 1)
  • np.random.randn(m, n) - standard normal
  • np.random.randint(low, high, size) - integers

Your Task

Write a function random_arrays(rows, cols, seed) that creates random arrays.

Important: Reset the generator with np.random.seed(seed) before generating each of the three arrays, so every array starts from the same seeded state (the expected outputs depend on this).

Output Format

Return a dictionary with:

  • "uniform": Uniform random (rounded to 2 decimals)
  • "normal": Normal distribution (rounded to 2 decimals)
  • "integers": Random integers from 0-9 (inclusive)

Each value is a nested list of shape rows × cols.

Example

Input
rows=2, cols=3, seed=42
Output
Arrays with reproducible random values
Reasoning
  • Inputs: rows = 2 and cols = 3 make every array a 2×32 \times 3 grid; seed = 42 fixes the starting state of the pseudo-random generator, so the result is arrays with reproducible random values.
  • Uniform: each entry is drawn from U[0,1)U[0, 1). Draws 0.3745,0.9507,0.7320,0.5987,0.15602,0.155990.3745, 0.9507, 0.7320, 0.5987, 0.15602, 0.15599 rounded to 2 decimal places give [[0.37, 0.95, 0.73], [0.6, 0.16, 0.16]] (0.5987→0.600.5987 \to 0.60, printed as 0.6).
  • Normal: entries come from N(0,1)\mathcal{N}(0, 1) so signs vary: 0.4967→0.50.4967 \to 0.5, −0.1383→−0.14-0.1383 \to -0.14, 1.5230→1.521.5230 \to 1.52, giving [[0.5, -0.14, 0.65], [1.52, -0.23, -0.23]].
  • Integers: each entry is equally likely to be any of 0,1,…,90, 1, \dots, 9 (never 10): [[6, 3, 7], [4, 6, 9]].
  • Notice: all three arrays restart from the seed-42 state rather than continuing the stream. The repeated 0.16 and -0.23 at the ends are a coincidence: two different draws that round alike. Without the reset, the normal array would start at 1.581.58 instead of 0.5.

Constraints

  • Always set seed first
  • Round floats to 2 decimal places
  • Integer range is 0-9 (inclusive)

More from NumPy Foundations

solution.py

Test results

Sign in to run your code against the test cases.