0Pricing
Data Science Academy · Lesson

Random Numbers and Seeds

Reproducible synthetic data with NumPy.

Random Numbers and Seeds is a free Data Science Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Generate Random Data

Real datasets are not always handy. Random numbers let you build test data, simulate scenarios, and shuffle samples on demand.

The Modern Generator

Start by creating a generator with default_rng. This is the current, recommended way to make random numbers in NumPy.

rng = np.random.default_rng()

Uniform Floats

Call random on the generator for floats between 0 and 1. Pass a size to get a whole array at once.

rng.random(3)   # 3 floats in [0, 1)

Random Integers

Use integers to draw whole numbers in a range. The low bound is included and the high bound is excluded.

rng.integers(1, 7, size=5)   # like dice rolls

Draw From a Normal Curve

The normal method samples a bell curve. Give it a mean and a standard deviation to shape the spread of values.

rng.normal(0, 1, size=4)

The Problem With Randomness

Run random code twice and you get different numbers. That breaks reproducibility when a teammate cannot recreate your results.

Seeds Fix the Sequence

A seed sets the generator to a known start. Same seed means the exact same numbers, every single run.

rng = np.random.default_rng(42)

Same Seed, Same Output

Two generators built with seed 42 produce identical arrays. That is how notebooks stay reproducible across machines.

a = np.random.default_rng(42).random(3)
b = np.random.default_rng(42).random(3)   # a == b

Shuffle and Sample

Generators also shuffle arrays and pick random samples with choice, perfect for splitting data or drawing test cases.

rng.choice([10, 20, 30], size=2)

Why It Matters for Science

Seeding makes experiments repeatable. Reviewers can rerun your code and confirm they see the very same outcome you reported.

Prefer the New API

You may still see the older np.random.seed style. New code should prefer the default_rng generator for cleaner, safer randomness.

Quick Check

A colleague reruns your notebook and gets different random results.

Randomness Recap

You generated floats, ints, and normal samples, then locked them with a seed so your results are reproducible anywhere. 🎲

Frequently asked questions

Is the “Random Numbers and Seeds” lesson free?

Yes — the full text of “Random Numbers and Seeds” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Random Numbers and Seeds”?

Reproducible synthetic data with NumPy. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Random Numbers and Seeds” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Reshape and Flatten Arrays
  2. Sum, Mean, and the Axis Trick
  3. Boolean Masks for Selection
  4. Random Numbers and Seeds
← Back to Data Science Academy