Fix bug in sample generator (dense case).