I try use as many things from the libraries in the standard distribution as possible.
If I can find high quality code available for my task at hand I will use that.
If what I can find is of sub-standard quality it may inspire me to do a rewrite
If I can't find it - like the ternary and fuzzy logics I published, hashes, PRNG's, audio filters, LFO's - I do a complete implementation from scratch and add it to my tool kit.
There are some things that I re-implement all the time because the algorithms are etched in my brains and I am too lazy to look it up, like singly and doubly linked lists and several types of trees. And sometimes I forgot that I already implemented something and one of the forum members alerts me that I wrote code for something myself years ago.
So basically, it depends.
But, a bit like you, I also tend to implement certain things from the math itself, especially if it is about data analyses or logic.
Professionally I wrote lot's of code in other languages, C(++), java, fortran, cobol, ada, basic, some of that not available, but implementable in Pascal, so nowadays I sometimes do that if I am bored. 47 years of code is a rich resource.
I still do some COBOL consultancy in the financial services industry and sometimes I might find some gems that I could probably do in Pascal.
side note : COBOL proficiency is a bit of a gold mine, so if you are there are many very well payed jobs available. There is not only a shortage, but outright starvation. You can basically ask what you want. Or if the industry knows you know COBOL you get offered ridiculous hourly rates. ( am now at a project with a major bank where I am the youngest at near 67..oldest is 75.. in the team.. so be versed in geriatrics)