improved random generation functions