I need to generate a (balanced) binary tree with a needle randomly placed on one of the nodes, so I can compare different blind search algoritms. I have generated the trees and the searches, but am struggling to work out how to randomly assign one of the nodes to be the needle. In order for the comparisons to be fair, the needle needs to approximate a random node, otherwise it can skew the results. (50% of needles should be on the lowest layer, etc.)
The best answer would be an algorithm that given the root node and the depth, it will assign a node as the needle, but other answers will be accepted.
Quick code dump of solution to help anyone in the future