| Долгих Данила RandBits 3191 | Ли Гэнцзэ 321 RandBits 3292 | ||||
|---|---|---|---|---|---|
| f | 1 | import random | f | 1 | import random |
| 2 | 2 | ||||
| 3 | def randbits(p, n): | 3 | def randbits(p, n): | ||
| 4 | if n > p or n <= 0: | 4 | if n > p or n <= 0: | ||
| 5 | return 0 | 5 | return 0 | ||
| 6 | positions = random.sample(range(p), n) | 6 | positions = random.sample(range(p), n) | ||
| n | 7 | result = 0 | n | 7 | num = 0 |
| 8 | for pos in positions: | 8 | for pos in positions: | ||
| t | 9 | result |= 1 << pos | t | 9 | num |= 1 << pos |
| 10 | return result | 10 | return num | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||