Thanks to Gabor, Francois, Peter D., Jari, Peter R.and John r2dtable is what I was looking for, it implements the Patefield algorithm. Patefield, W. M. (1981) Algorithm AS159. An efficient method of generating r x c tables with given row and column totals. Applied Statistics 30, 91 97. This definitely made my day! Cheers Yann