When three men share ownership of a slave woman, and they all have intercourse with her in a single period of purity, and she gives birth to a child, and they all claim the child, then lots are to be cast among them. Whoever wins the child by the lot will pay the others two-thirds of the blood money.
Zayd ibn Arqam (may Allah be pleased with him) said: Three men were brought to Ali (may Allah be pleased with him) while he was in Yemen, who had all had intercourse with one woman (a slave woman) in a single period of purity. He said to two of the men, “Do you acknowledge the child as belonging to this (third) one?” They said, “No.” He asked them all in the same way, but whenever he asked two of the men, they said, “No.” Then he cast lots among them and attached the child to the man whose name came out in the lot, and he also made two-thirds of the blood money obligatory upon him (to pay to the other two). The narrator says: This was reported to the Messenger of Allah ﷺ, and he laughed so much that his molar teeth appeared.
[Sahih: Sahih Abi Dawud: 1987, Kitab al-Talaq: Bab man qala bil-qur’a idha tanaza’u fil-walad, Abu Dawud: 2270, Ahmad: 374/4, Nasa’i: 182/6, Humaydi: 785, Ibn Majah: 2348]
(The majority of scholars, Malik (may Allah have mercy on him), Shafi’i (may Allah have mercy on him), Ahmad (may Allah have mercy on him)) hold that casting lots is permissible (in every case).
[Nayl al-Awtar: 381/4]
The Prophet ﷺ also took lots into account in other matters of the Shariah, as when a man freed six slaves, the Prophet ﷺ divided them into three parts, then cast lots among them, and freed those whose names came out in the lot.
[Muslim: 1668, Kitab al-Iman: Bab man a’taqa shirkan lahu fi ‘abd, Abu Dawud: 3958, Tirmidhi: 1364, Ibn Majah: 2345, Nasa’i: 64/4]