how do I make a solenoid operate after a random number of switch presses
Configure a 555 timer for a 91% duty cycle and latch the output.

Feed the output of the timer into a D flip-flop.
Use a double pole switch.  The first pole of the switch is used as the clock for the flip flop.  When the button is pressed the flip-flop will latch whatever value was on the clock pulse.  There will be a 9% chance that the output was low.  A low output on the timer will result in the flip-flop output being high.  This will turn on the 2N7000 MOSFET.  The MOSFET may be used to drive the solenoid directly, or if required it can drive a relay.  The second pole of the switch is put in series with the solenoid so that the solenoid only remains on as long as the button is pressed.

In total the cost of the parts should be under $5.







simulate this circuit &ndash; Schematic created using CircuitLab

Component links

SE555P
https://www.digikey.com/product-detail/en/texas-instruments/SE555P/296-9684-5-ND/380221

CD4013BE
https://www.digikey.com/product-detail/en/texas-instruments/CD4013BE/296-2033-5-ND/67245

EC2-4.5NU
https://www.digikey.com/product-detail/en/kemet/EC2-4.5NU/399-11046-5-ND/4291112

2N7000-G
https://www.digikey.com/product-detail/en/microchip-technology/2N7000-G/2N7000-G-ND/4902350