The script probably works better if all nicks joining #chanA are known by the bot in #chanB, and might even work better if the same bot is in both channels. For one thing, BotB needs to know which of the joined nicks is already in #chanB. If you're wanting to invite every 20th nick, you can have a counter (as a global variable or in a hashtable) which is incremented before each join to #chanA, then invites only when the counter is either 1 for the 1st of 20, or when the counter is at 20 for the last of 20. When the counter is above 20, it must be replaced by 1. You can also use "if ($rand(1,20) == 1)" to decide whether to invite each nick, but that will have random results, and after 20 joins to A could result in zero invites or 20 invites, though the most likely result is 1 join.
Things get a little more complicated if you need to resist "gaming the system", such as someone doing a /part-then-/join repeatedly until they win the invite lottery.
I'm curious how this actually works in practice, since the invite shows in status window unless you've checkboxed "options/irc/show-in-active=invite". Most people do not enable the "auto join channel on invite" option because it's not selective as to which joins are accepted, and people would rather auto-join nothing instead of finding themselves suddenly having a join window popping up for some unwanted channel.