Hi CB
I'm not sure I understand your problem. If I'm right, you want to create a game with kind of the same mechanic as "Jetpack Joyride", which create random scenes/environments every few screens. When working on a game, I would advise you to visualize what you want to do.
(Please keep in mind that it's only how I would do it, but you can make your own better solution).

(It's through the editor, not though)
I believe that with this way of doing it, your problem of the generation only working sometimes should disappear.
Does it seem right to you?
Btw, if you're discovering the randi()% function, I would advise you to call randomize() at the start of your game, it will create a random set of number for your randi()% to use.