Skip to content

Commit 23bc7b9

Browse files
committed
update random data generation tutorial
1 parent c8928c2 commit 23bc7b9

File tree

1 file changed

+10
-0
lines changed
  • python-standard-library/generating-random-data

1 file changed

+10
-0
lines changed

python-standard-library/generating-random-data/generate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import string
44
import secrets
55

6+
import numpy as np
7+
68
# generate random integer between a and b (including a and b)
79
randint = random.randint(1, 500)
810
print("randint:", randint)
@@ -19,6 +21,14 @@
1921
choices = random.choices(range(1000), k=5)
2022
print("choices:", choices)
2123

24+
# get a random vector of size 20
25+
vector = np.random.random((30,))
26+
print("vector:\n", vector)
27+
28+
# get a random matrix of size (3, 3) in the range [0, 100]
29+
matrix = np.random.random((3, 3)) * 100
30+
print("matrix:\n", matrix)
31+
2232
# generate a random floating point number from 0.0 <= x <= 1.0
2333
randfloat = random.random()
2434
print("randfloat between 0.0 and 1.0:", randfloat)

0 commit comments

Comments
 (0)