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. The game might also have a number that always counts up and you could have it turn on or off accordingly, or if you are lucky and there are two numbers you can do a if this is greater than this AND this value is odd then execute. I don't have a particularly good source of constant randomness on the DS -- some might try the microphone but eh.
3) Have turn on and turn off set to different button combos (possibly single button) that you will hit during play. Randomise these button combos a bit so you don't know what does what and add them as the
cheats. Eventually you might figure out what does it for that game but you can always change for next time. It should be possible to have multiple buttons doing different things. You could even combine it with 2) in some manner to only turn on when a given number in the game is odd or even, greater than/less than a given number or something like that.