I don't think there is a specific function within any cheat code setup on cheat carts themselves, flash carts or homebrew offerings.
Three main approaches are then that I would consider.
1) You port the code in question to assembly and have a random on-off there. If you can port the code to assembly then this is two steps more.
2) You make some kind of accumulator in the AR code. This way it shuffles on and off every so many frames or whatever.
How to make a code randomly execute? Help would be appreciated!