It might be by analogy, a technique from a different domain, from similarity with something you did with lego blocks when you were 9 years old, from a mishearing when discussing something with a fellow developer, from ignorance of the known techniques in a particular area and trying to solve it from first principles, etc. You do need some familiarity and experience in the domain in order to recognize the utility of the novel technique. It might happen once to you, but it's unlikely to happen 9 times.
More importantly, it's also probably going to occur to someone else, sooner or later. New discoveries tend to be repeated, that's a common theme in the history of scientific and mathematical development. By advocating patents for these things, you suggest the mere chance of coming first means you get a government-granted right to extort from other people.