We present a linear algorithm which generates randomly and with unifor
m probability many kinds of trees: binary trees, ternary trees, arbitr
ary trees, forests of p k-ary trees,.... The algorithm is based on the
definition of generic trees which can be coded as words. These words,
in turn, are generated in linear time.