| Власов Алексей Олегович 181дса RandBits 3135 | Ващенко Алёна Дмитриевна, 418 гр. RandBits 2836 | ||||
|---|---|---|---|---|---|
| f | 1 | import random | f | 1 | import random |
| 2 | 2 | ||||
| 3 | def randbits(p, n): | 3 | def randbits(p, n): | ||
| 4 | if n > p: | 4 | if n > p: | ||
| 5 | return 0 | 5 | return 0 | ||
| t | 6 | check = random.sample(range(p), n) | t | 6 | ones_positions = random.sample(range(p), n) |
| 7 | result = 0 | 7 | number = 0 | ||
| 8 | for i in check: | 8 | for position in ones_positions: | ||
| 9 | result |= 1 << i | 9 | number |= 1 << position | ||
| 10 | return result | 10 | return number | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||