TikZ/PGF decoration that adds noise only to y coordinate

After some diagrams in a napkin and a little of trigonometry (which I can explain if you are interested), I arrived at: (see edit at the end)

\documentclass[varwidth,convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\pgfdeclaredecoration{jiggly}{step}
{
  \state{step}[width=+\pgfdecorationsegmentlength]
  { \pgfmathsetmacro{\delta}{rand*\pgfdecorationsegmentamplitude}
    \pgfmathsetmacro{\deltax}{\delta*cos(90+\pgfdecoratedangle}
    \pgfmathsetmacro{\deltay}{\delta*sin(90+\pgfdecoratedangle}
    \pgfpathlineto{\pgfpoint{\pgfdecorationsegmentlength-\deltax}{\deltay}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\pgfmathsetseed{1}
\begin{tikzpicture}[very thick, decoration={jiggly, amplitude=1cm}]
\draw[help lines] (0,0) grid (7,4);
\draw[cyan, decorate] (0,1) -- (3,1);
\draw[red, decorate] (4,0) -- (7,3);
\end{tikzpicture}
\end{document}

Result:

Result

EDIT

After comparing my code to the OP's one, I noticed that in the end I was doing the same, only computing myself the "projections" of the random noise on the appropiate direction, instead of letting pgf polar transformation to do the same. So... why my code works and the OP's one doesnt?

The only reasonable explanation to me was that rand was being used as second argument for \pgfpointpolar and, perhaps, when pgf is translating polar coordinates to cartesian coordinates, and thus computing sines and cosines, this parameter was evaluated twice (one per each axis), giving different rand result in each evaluation.

So I tested this idea by mading a simple modification to OP's code, which ensures that rand is evaluated once:

\pgfdeclaredecoration{jiggly}{step}
{
  \state{step}[width=+\pgfdecorationsegmentlength]
  {\pgfmathsetmacro{\delta}{rand*\pgfdecorationsegmentamplitude}
    \pgfpathlineto{
      \pgfpointadd
      {\pgfpoint{\pgfdecorationsegmentlength}{0pt}}
      {\pgfpointpolar{90-\pgfdecoratedangle}
          {\delta}}
    }
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

And it worked too!


Another (simpler?) solution:

\documentclass[varwidth,convert]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\pgfdeclaredecoration{jiggly}{step}
{
  \state{step}[width=+\pgfdecorationsegmentlength]
  {
    \pgfmathsetmacro{\r}{rand*\pgfdecorationsegmentamplitude}
    \pgfpathlineto{\pgfpointadd{\pgfpointpolar{90-\pgfdecoratedangle}{\r}}{\pgfpoint{\pgfdecorationsegmentlength}{0pt}}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\pgfmathsetseed{1}
\begin{tikzpicture}[very thick, decoration={jiggly, amplitude=1cm}]
\draw[help lines] (0,0) grid (7,4);
\draw[cyan, decorate] (0,1) -- (3,1);
\draw[red, decorate] (4,0) -- (7,3);
\end{tikzpicture}

\end{document}

With \pgfpointadd I add the noise relatively to the end point.