The Messenger of Allah ﷺ forbade the sale by pebble-throwing and the sale involving uncertainty.
نهي رسول الله ﷺ عن بيع الحصاة، وعن بيع الغرر.
Muslim narrated it in the Book of Sales (1513) through several routes from Ubaydullah, who said, "Abu Zinad told me, from Araj, from Abu Hurairah," who mentioned it as stated.Nawawi said in his commentary on Muslim (10/155-156), "The sale of the pebble has three interpretations. The first is that he says, 'I sell you whichever of these garments the pebble I throw lands on,' or 'I sell you from this land, from here to wherever this pebble reaches.' The second is that he says, 'I sell to you on condition that you have the choice until I throw this pebble.' The third is that they make the very act of throwing the pebble itself the sale, so he says, 'When I throw this pebble at this garment, it is sold to you for such and such.'As for the prohibition of selling with gharar, it is one of the great foundational principles among the principles of the Book of Sales, and this is why Muslim placed it first. Many matters fall under it, without limit, such as the sale of a runaway slave, the sale of something nonexistent, the sale of something unknown, the sale of what one cannot deliver, the sale of what is not yet fully owned by the seller, the sale of fish in a large body of water, milk while still in the udder, the sale of an unborn fetus in the womb, the sale of an unspecified portion of a heap, the sale of one garment among several garments, one sheep among several sheep, and similar cases. All of these sales are invalid, because they involve gharar without any need for it.However, some degree of gharar may be tolerated in a sale when there is a need for it, such as not knowing the foundation of a house, or as when someone sells a pregnant sheep, or one whose udder contains milk, for in such cases the sale is valid, because the foundation is treated as part of what is visible of the house, and because necessity calls for it, since it cannot actually be seen. The same applies to the fetus of the sheep and its milk."