Add randomization in RI flow graph construction.

This makes it (empirically) much more likely for corresponding R to
exist.
Unbreak tests.
Make balanceness tests stricter again.
Make several attempt of generating RI.

Also make number of attempts configurable through CLI flags.
Move retrying logic for R to BuildR.
Extract function for generating (and possibly retrying) RI and R.

For use in tests.