I'm wondering how did Andy write the letter to Red before actually going to prison in The Shawshank Redemption? He tells Red how to find it and tells him about the black rock, so from what I understand he wrote the letter before going to prison. However he couldn't possibly have known Red. So I want to know when was the letter actually written?
No. He actually didn't write Red the letter from or before prison, but after he ran away from the prison.
You must have gotten confused when Andy told Red to find the black rock and the letter. Actually, he accomplished that after getting free from the prison. There was significant time between Andy breaking out and Red getting freed. One can easily write a letter in that time.
Though, he well remembers that place because Andy asked his wife to marry him at that place.
ANDY: Red, if you ever get out of here, do me a favor. There's this big hayfield up near Buxton. You know where Buxton is?
RED: (nods) Lots of hayfields there.
ANDY: One in particular. Got a long rock wall with a big oak at the north end. Like something out of a Robert Frost poem. It's where I asked my wife to marry me. We'd gone for a picnic. We made love under that tree. I asked and she said yes.
ANDY: (continues) Promise me, Red. If you ever get out, find that spot. In the base of that wall you'll find a rock that has no earthly business in a Maine hayfield. A piece of black volcanic glass. You'll find something buried under it I want you to have.