improved random generation