MCPcopy
hub / github.com/joowani/binarytree / _generate_random_leaf_count

Function _generate_random_leaf_count

binarytree/__init__.py:1843–1857  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1841
1842
1843def _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
1860def number_to_letters(number: int) -> str:

Callers 2

treeFunction · 0.85
bstFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected