Reveal cards from the top of your library until you reveal an artifact card. Put that card onto the battlefield and the rest on the bottom of your library in a random order. Madcap Experiment deals damage to you equal to the number of cards revealed this way.
Any abilities that trigger as the artifact enters the battlefield aren't put onto the stack until Madcap Experiment is done resolving.
If you don't reveal an artifact card, you'll randomize your library and be dealt damage equal to the number of cards in your library.
Once Madcap Experiment begins resolving, no player may take any actions other than those specified by Madcap Experiment until it's done resolving.
The number of cards revealed this way includes the artifact card you put onto the battlefield.