The answer is right there in the citation. Scroll down to the javadocs:
* @param r upper bound for the random range
It sounds to me like r
ought to be the number of nodes in the tree. Do you agree?
I'm randomly selecting nodes from a
Binary Tree and I have to build a
black-box test that proves all nodes
have the nearly the same probability
of being selected.
I don't understand this. Do you? It seems less a test of the tree data structure and more about the random algorithm you use to choose a node to be selected. What does this outcome prove?
Walk me through what you're doing, please. Here's what I'm imagining:
- You have a list of nodes in your tree.
- You use a random algorithm somehow to choose a node to select from your tree.
- You iterate through your tree to find that node.
If there are r
nodes in your tree, each one should have 1/r probability of being selected. It's a multi-dimensional, r-sided coin or die. Right?
The tree could bring another element into the mix: the probabilities are changed if the chances of being selected depend on where you are in the tree and whether or not you're allowed to backtrack. If that's the case, the chances of being selected are different at each node. Starting at the root means you can get to all child nodes. Being on the first level and not being able to backtrack eliminates the root and all other first level nodes from consideration, and so on.
Which problem are you trying to solve?