There are a couple of outstanding answers here already, I'm just going to address the "cannot be learnt" fallacy, because it just might be well-intentioned.
I understand what is meant by "cannot be learnt", and disagree, I think it would be better to present the argument as "cannot be taught". Like, nobody taught you to walk, or ride your bike, they just gave you endless encouragement until you got there yourself. So here I go...
You wish to create something completely original, easy, anybody could do it, nobody needs to teach you to do that, so... there are probably a few additional requirements:
- You probably would like to create something that you would like to hear again.
- You need to be able to remember how to play it.
I would like to hear that again!
Why? So, I assume it wasn't a collection of random notes. Why wasn't it random to you? Even if all the notes belong to a key, scale, mode, even if they harmonize with a chord progression, they can still be random, just random within those constraints.
When you heard those notes for the first time, something unusual happened, they made sense, even at the abstract level, you somehow understood that thing you just did, as if they told a story, and you liked it. Which is fantastic! That's the desired result. I wish I could tell you how to do that, at will, and prolifically pen meaningful melody.
You can part with good money on books and courses that claim to teach just that, be my guest, but I think such material would be best-sellers if they really worked.
Now, how did I play it?
Enter music theory. Especially scales, keys, modes, chords, harmony, rhythm... based on centuries of observation of musical phenomenon.
This will help you make sense of the mechanics of your melody more easily, it's not impossible to do this without any explicit musical knowledge, many people do, but it can reduce the time to find things you would like to hear again, and help you to mentally structure the information about your music so that you can remember how to play it. Excellent.
However, did music theory teach you how to create a melody? It certainly didn't hurt, but in itself, I'm not sure it provides the 'creative spark', the imagination, the ideas. Of course, it could have, since anything can, but in my experience, creativity 'just happens', there is no formula, no secret to success, no hard and fast rules, you just do it.
If you cannot naturally mentally conceptualize an original melody (for example, if you are reading candidate lyrics and cannot 'hear' the melody you think would fit it well), it's nothing to worry about, that's only one technique, there are countless others (e.g. free play).
Music theory provides a framework, but don't expect it to be a portal into creating original melody. Music theory can give you constraints for your music, and in certain situations, being constrained can be a creative boost (e.g. try making a melody from 4 random pitches - you'd be surprised how many people can pull that off).
Conversely, removing constraints is another method to boost creativity, studying a musical concept that is unfamiliar to you can broaden your horizon and draw in new inspiration. Any shift to a new perspective can contribute to creativity, even non-musical changes, an emotional event in your life, for example.
Many artists have confessed at some time that "the melody just came", as if it was a divine experience. There is also the aspect of when trying to force creativity, it becomes blocked. Apparently, even boredom can help creativity!