- Главная
- Английский язык
- Return random integer in range [a, b], including both end points
Содержание
- 2. sample Chooses k unique random elements from a population sequence or set. Returns a new list
- 3. shuffle Shuffle list x in place, and return None. Optional argument random is a 0-argument function
- 4. choices Return a k sized list of population elements chosen with replacement. If the relative weights
- 6. Скачать презентацию
Слайд 2
sample
Chooses k unique random elements from a population sequence or set.
sample
Chooses k unique random elements from a population sequence or set.
Returns a new list containing elements from the population while
leaving the original population unchanged. The resulting list is
in selection order so that all sub-slices will also be valid random
samples. This allows raffle winners (the sample) to be partitioned
into grand prize and second place winners (the subslices).
Members of the population need not be hashable or unique. If the
population contains repeats, then each occurrence is a possible
selection in the sample.
Repeated elements can be specified one at a time or with the optional
counts parameter. For example:
sample(['red', 'blue'], counts=[4, 2], k=5)
is equivalent to:
sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)
To choose a sample from a range of integers, use range() for the
population argument. This is especially fast and space efficient
for sampling from a large population:
sample(range(10000000), 60)
leaving the original population unchanged. The resulting list is
in selection order so that all sub-slices will also be valid random
samples. This allows raffle winners (the sample) to be partitioned
into grand prize and second place winners (the subslices).
Members of the population need not be hashable or unique. If the
population contains repeats, then each occurrence is a possible
selection in the sample.
Repeated elements can be specified one at a time or with the optional
counts parameter. For example:
sample(['red', 'blue'], counts=[4, 2], k=5)
is equivalent to:
sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)
To choose a sample from a range of integers, use range() for the
population argument. This is especially fast and space efficient
for sampling from a large population:
sample(range(10000000), 60)
Слайд 3
shuffle
Shuffle list x in place, and return None.
Optional argument random
shuffle
Shuffle list x in place, and return None.
Optional argument random
is a 0-argument function returning a
random float in [0.0, 1.0); if it is the default None, the
standard random.random will be used.
random float in [0.0, 1.0); if it is the default None, the
standard random.random will be used.
Слайд 4
choices
Return a k sized list of population elements chosen with replacement.
choices
Return a k sized list of population elements chosen with replacement.
If the relative weights or cumulative weights are not specified,
the selections are made with equal probability.
the selections are made with equal probability.
- Предыдущая
Словообразование наречийСледующая -
Основные принципы реанимации новорожденных