"One for sorrow" magpie rhyme

I’m sure this has been done before.

Why do we say:
“One for Sorrow,
Two for Joy,
Three for a Girl,
Four for a Boy,
Five for Silver,
Six for Gold.,
Seven for a Secret never to be told.” when we see magpies?
I’ve also heard the rhyme with Three for a Letter, and Eight for a Babe buried in the dark.

I’m guessing it’s a pagan/druid type thing, but I’m not sure.

Anyone know?