| Анастасия Иванова, группа 517 RandBits 3558 | Sabua8 RandBits 3146 | ||||
|---|---|---|---|---|---|
| n | 1 | import random as ran | n | 1 | import random |
| 2 | 2 | ||||
| 3 | def randbits(p, n): | 3 | def randbits(p, n): | ||
| 4 | if n < 1 or n > p: | 4 | if n < 1 or n > p: | ||
| 5 | return 0 | 5 | return 0 | ||
| t | 6 | poses = ran.sample(range(p), n) | t | 6 | positions = random.sample(range(p), n) |
| 7 | ran_p = 0 | 7 | result = 0 | ||
| 8 | for pos in poses: | 8 | for pos in positions: | ||
| 9 | ran_p |= 1 << pos | 9 | result |= 1 << pos | ||
| 10 | return ran_p | 10 | return result | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||