How to get a random node from a tree?

Posted by ooboo on Stack Overflow See other posts from Stack Overflow or by ooboo
Published on 2010-04-04T10:41:54Z Indexed on 2010/04/04 10:43 UTC
Read the original article Hit count: 139

Filed under:
|
|
|

It looks easy, but I found the implementation tricky. I need that for a simple genetic programming problem I'm trying to implement. The function should, given a node, return the node itself or any of its children such that the probability of choosing a node is normally distributed relative to its depth (so the function should return mostly middle nodes, but sometimes the root itself or the lowest ones - but that's not really necessary if that makes it significantly more complex, if all any node is chosen with equal probability, that's good enough).

Thanks

© Stack Overflow or respective owner

Related posts about ranom

Related posts about node