“Willy Nilly” is an idiom has two slightly related but different meanings. When it was first coined, it meant to do something with or against one’s will; or another way of saying “it really doesn’t matter to me.”
The modern and commonly used meaning is to do something in a haphazard manner.
Example: “This business deal is bound to fall through. Everything has been done utterly willy nilly.”
It’s derived from “will I nill I or will ye nill ye or will he nill he.”
Where does it come from?
In old English “nill” was the opposite of will; a contraction of ‘ne will’. “Will” meant the desire to something and “nill” was the desire to avoid it. It can be translated to:
“be ye willing, be ye unwilling.”
The Latin phrase “nolens volens” also means the same thing, although it’s not known for sure if the English phrase is a direct translation. There is also a very old saying “hitty missy” which also has the same meaning.
“Willy nilly” first appeared in the Old English text, Aelfric’s Lives of Saints, circa 1000:
“Forean the we synd synfulle and sceolan beon eadmode, wille we, nelle we.”
Petruchio: [To Katharina]
Thus in plain terms: your father hath consented
That you shall be my wife; your dowry ‘greed on;
And, Will you, nill you, I will marry you.
[I.e. I will marry you, whether you like it or not.]
and again, in Hamlet:
First Clown: Give me leave. Here lies the water; good: here stands the man; good; if the man go to this water, and drown himself, it is, will he, nill he, he goes.
[I.e. If a man chooses to drown he enters the water, if he chooses not, he leaves.]
The modern use of “willy nilly” to mean something done haphazardly evolved from the “will-less” aspect of the older meaning.