Concept Flow - Uniform random with random()
Call np.random.random()
Return random float
Use or store the float
Repeat if needed
The function np.random.random() generates a random float between 0 and 1 each time it is called.
import numpy as np x = np.random.random() print(x)
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Call np.random.random() | Generates a random float in [0,1) | 0.3745401188473625 |
| 2 | Assign to variable x | x = 0.3745401188473625 | x holds 0.3745401188473625 |
| 3 | Print x | Output the value of x | Prints 0.3745401188473625 |
| 4 | End | No more code | Execution stops |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| x | undefined | 0.3745401188473625 | 0.3745401188473625 | 0.3745401188473625 |
np.random.random() generates a float in [0,1). Each call returns a new random number. Use it to get uniform random floats. Assign to variables to store values. Useful for simulations and sampling.