Add following in $HOME/.zshrc

function color {
  case $1 in
    random)
      t=$((( RANDOM % 256 ) ))
      echo -e "\033]6;1;bg;red;brightness;${t}\a"
      t=$((( RANDOM % 256 ) ))
      echo -e "\033]6;1;bg;green;brightness;${t}\a"
      t=$((( RANDOM % 256 ) ))
      echo -e "\033]6;1;bg;blue;brightness;${t}\a"
    ;;
  esac
}

color random