0
0
MLOpsdevops~10 mins

Random seed management in MLOps - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Random seed management
Set random seed
Initialize random generator
Run stochastic process
Get reproducible output
Use output for training/testing
Repeat with same seed -> same results
Change seed -> different results
This flow shows how setting a random seed fixes the starting point of randomness, making results repeatable across runs.
Execution Sample
MLOps
import random
random.seed(42)
print(random.randint(1, 10))
print(random.randint(1, 10))
This code sets a random seed and prints two random numbers, which will be the same every time it runs.
Process Table
StepActionSeed StateRandom Number GeneratedOutput
1Set seed to 42Seed=42N/ANo output
2Generate first random intSeed=42 (updated internally)Random int between 1-102
3Generate second random intSeed=updatedRandom int between 1-101
4End of executionSeed=updatedN/AOutputs: 2, 1
💡 Random numbers generated based on seed 42, ensuring reproducibility.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
seedNone42internal updatedinternal updatedinternal updated
random_number_1NoneNone222
random_number_2NoneNoneNone11
Key Moments - 3 Insights
Why do the random numbers stay the same every time we run the code?
Because setting the seed (Step 1) fixes the starting point of the random number generator, so the sequence of numbers generated (Steps 2 and 3) is always the same.
What happens if we don't set a seed before generating random numbers?
Without setting a seed, the random number generator starts from a different state each time, so the numbers will differ on each run (not shown in table but implied).
Does the seed variable itself change after generating numbers?
The seed is used to initialize the generator; internally the generator state updates after each number, but the original seed value remains conceptually fixed (see 'internal updated' in variable_tracker).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the first random number generated at Step 2?
A2
B1
C42
DNone
💡 Hint
Check the 'Random Number Generated' and 'Output' columns at Step 2 in the execution_table.
At which step does the seed get set to 42?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the 'Action' column in the execution_table to find when the seed is set.
If we change the seed to 100, what will happen to the output numbers?
AThey will be the same as with seed 42
BNo numbers will be generated
CThey will be different from seed 42
DThe seed will reset to 42 automatically
💡 Hint
Refer to the concept_flow where changing the seed leads to different results.
Concept Snapshot
Random seed management:
- Use random.seed(value) to fix randomness
- Fixing seed makes outputs reproducible
- Same seed = same random sequence
- Different seed = different sequence
- Useful for debugging and consistent experiments
Full Transcript
Random seed management means setting a starting point for random number generation so results repeat every time. We set the seed using random.seed(42). Then, when we generate random numbers, they come out the same on every run. This helps in machine learning experiments to get consistent results. The seed initializes the random generator's state. Each call to generate a random number updates this state internally. If we change the seed, the sequence of random numbers changes. Without setting a seed, the numbers vary each run. This trace showed setting seed 42 and generating two random numbers: 2 and 1, always the same on every run.