# Numbering Procedure and Algorithm Independently in algorithm2e

I want to use algorithm2e to generate two procedure and two algorithm. The procedure and algorithm may be interleaved with one another, and both procedure and algorithm have their independent counter number.

I used the option procnumbered to algorithm2e so that the procedure environment can be numbered, but I find another problem: the procedure and algorithm environment only share one counter number. How can I number these two environments separately, each with its own counter?

As an example, how can I number the procedure as 1, and the algorithm as 1 too (not 2). Thanks.

\documentclass{article}
\usepackage[procnumbered,ruled]{algorithm2e}
\begin{document}

\begin{procedure}
\caption{myproc()}
This is a procedure
\end{procedure}

\begin{algorithm}
\caption{My algorithm}
This is a procedure
\end{algorithm}

\end{document}


Both environments use the algocf counter; you can teach LaTeX to use another one for procedures.

\documentclass{article}
\usepackage[procnumbered,ruled]{algorithm2e}
\usepackage{etoolbox}
\newcounter{procedure}
\makeatletter
\AtBeginEnvironment{procedure}{\let\c@algocf\c@procedure}
\makeatother
\begin{document}

\begin{procedure}[!htp]
\caption{myproc()}
This is a procedure
\end{procedure}

\begin{algorithm}[!htp]
\caption{My algorithm}
This is a procedure
\end{algorithm}

\begin{procedure}[!htp]
\caption{myproc()}\label{aproc}
This is a procedure
\end{procedure}

\begin{procedure}[!htp]
\caption{myproc()}
This is a procedure
\end{procedure}

\begin{algorithm}[!htp]
\caption{My algorithm}
This is a procedure
\end{algorithm}

Procedure~\ref{aproc}

\end{document}