Generalised gen function