The draw was made at Hampden in the last few minutes.
Ton have been rewarded with a home tie after beating Celtic in a stunning cup upset on Tuesday night.
Ties are scheduled to be played on either 29 or 30 October.
The full draw is as follows:
INVERNESS CALEDONIAN THISTLE v DUNDEE UNITED
MORTON v ST. JOHNSTONE
HIBERNIAN v HEART OF MIDLOTHIAN
MOTHERWELL v ABERDEEN