Ali bin Abu Talib, while he was in Yemen, was brought a case involving three men who had all had relations with the same woman during a single period of purity. He asked two of them, "Do you both acknowledge this child as belonging to him?" They said, "No."Then he asked another two, "Do you both acknowledge this child as belonging to him?" They said, "No."Each time he asked two of them, "Do you both acknowledge this child as belonging to him?" they said, "No."So he drew lots between them and assigned the child to the one whose lot was drawn, and he required him to pay two-thirds of the blood-money. This was mentioned to the Prophet ﷺ, and he laughed until his back teeth showed.
حدثنا إسحق بن منصور أنبأنا عبد الرزاق أنبأنا الثوري عن صالح الهمداني عن الشعبي عن عبد خير الحضرمي
أتي علي بن أبي طالب وهو باليمن في ثلاثة قد وقعوا على امرأة في طهر واحد فسأل اثنين فقال أتقران لهذا بالولد فقالا لا ثم سأل اثنين فقال أتقران لهذا بالولد فقالا لا فجعل كلما سأل اثنين أتقران لهذا بالولد قالا لا فأقرع بينهم وألحق الولد بالذي أصابته القرعة وجعل عليه ثلثي الدية فذكر ذلك للنبي ﷺ فضحك حتى بدت نواجذه
Its isnad is daif. Abu Dawud narrated it in the Book of Divorce, chapter "Whoever said drawing lots when they dispute over the child," hadith 2270, from the hadith of Abdul-Razzaq with this wording, and its chain is daif because of Thawri's use of an ambiguous form of transmission (anana), hadith 162, and it has daif corroborating narrations.