12.3. Math Random¶
12.3.1. random
¶
Function |
Description |
---|---|
|
Random float: 0.0 <= x < 1.0 |
|
Return a random integer N such that |
|
Gaussian distribution. mu is the mean, and sigma is the standard deviation |
|
Randomize order of list (in place) |
|
Single random element from a sequence |
|
k random elements from list without replacement |
|
Initialize the random number generator. If a is omitted or None, the current system time is used |
12.3.2. Pseudo and Pure random numbers¶
What are pseudorandom numbers?
Why it is not possible to generate a pure random number?
What is
random.seed(0)
?
12.3.3. Assignments¶
12.3.3.1. Random numbers¶
Assignment: Random numbers
Complexity: easy
Lines of code: 5 lines
Time: 13 min
- English:
Print 6 random integers without repetition in range from 1 to 49
- Polish:
Wyświetl 6 losowych i nie powtarzających się liczb całkowitych z zakresu od 1 do 49.
12.3.3.2. Sum of inner elements¶
Assignment: Sum of inner elements
Complexity: medium
Lines of code: 5 lines
Time: 13 min
- English:
Use only
random
moduleSet
random.seed(0)
Generate
outer: list[list[int]]
with 16x16 random digits (0-9 inclusive)Calculate sum of inner 4x4 elements
Inner matrix is exactly in the middle of outer
- Polish:
Używaj tylko modułu
random
Ustaw
random.seed(0)
Wygeneruj
outer: list[list[int]]
z 16x16 losowych cyfr (0-9 włącznie)Policz sumę środkowych 4x4 elementów
Środkowa macierz jest dokładnie w środku większej

Figure 12.2. Sum of inner elements¶