Return a random leaf count for building binary trees. :param height: Height of the binary tree. :type height: int :return: Random leaf count. :rtype: int
(height: int)
| 1841 | |
| 1842 | |
| 1843 | def _generate_random_leaf_count(height: int) -> int: |
| 1844 | """Return a random leaf count for building binary trees. |
| 1845 | |
| 1846 | :param height: Height of the binary tree. |
| 1847 | :type height: int |
| 1848 | :return: Random leaf count. |
| 1849 | :rtype: int |
| 1850 | """ |
| 1851 | max_leaf_count = 2**height |
| 1852 | half_leaf_count = max_leaf_count // 2 |
| 1853 | |
| 1854 | # A very naive way of mimicking normal distribution |
| 1855 | roll_1 = random.randint(0, half_leaf_count) |
| 1856 | roll_2 = random.randint(0, max_leaf_count - half_leaf_count) |
| 1857 | return roll_1 + roll_2 or half_leaf_count |
| 1858 | |
| 1859 | |
| 1860 | def number_to_letters(number: int) -> str: |