2.3. Random About

2.3.1. random

Table 2.3. random

Function

Description

random.shuffle(list)

Randomize order of list (in place)

random.choice(list)

Single random element from a sequence

random.sample(list, k)

k random elements from list without replacement

2.3.2. Assignments

Code 2.24. Solution
"""
* Assignment: Random Select Sample
* Complexity: easy
* Lines of code: 1 lines
* Time: 3 min

English:
    1. Define `result: list[int]` with 6 random
       integers without repetition in range from 1 to 49 (inclusive)
    2. Use `random.sample()`
    3. Run doctests - all must succeed

Polish:
    1. Zdefiniuj `result: list[int]` z 6-oma losowymi
       i nie powtarzającymi się liczbami całkowitymi
       z zakresu od 1 do 49 (włącznie)
    2. Użyj `random.sample()`
    3. Uruchom doctesty - wszystkie muszą się powieść

Tests:
    >>> import sys; sys.tracebacklimit = 0

    >>> sorted(result)
    [3, 17, 25, 27, 32, 33]
"""

from random import sample, seed
seed(0)

# type: list[int]
result = ...

../../_images/random-inner-sum1.png

Figure 2.1. Sum of inner elements