Yes. I actually knew and frequently talked with many of the homeless people who lived near me when I lived in downtown SF. The thing is that opiates are naturally cheap, and most of the current cost comes from heavy regulation.
If an addict can be high all day for a quarter the cost of a meal, say $1, and can purchase said from a safe, reputable drug store in their chosen location, rather than trekking across town to a shady area to buy illegal drugs from a outlaw dealer, they’ll do that. If only because they can spend more time begging and less time walking.
You have a very skewed view of addicts if you think they are that deranged. A good illustration of that is clean needle programs that provide orange safety tips for used needles. If these addicts were so completely deranged, those tips would end up in the trash not on the ends of needles in the streets.
Only when you are sane. Did you know addicts are willing to walk on street @20F to get some money for drug instead of going shelters?
This is quite common and not hard to observe once you are willing to explore a bit beyond your regular happy life.