Currently, the C core uses the BEGIN_RNG() and END_RNG() macros to ensure that GetRNGState() / PutRNGstate() are called. Managing this from the C core is quite difficult:
- Nested
GetRNGState() / PutRNGstate() pairs will lead to reduced randomness, as discussed at https://igraph.discourse.group/t/consistency-of-rng-begin-and-rng-end/641 Avoiding nesting is problematic because it limits function reuse.
- The pressure to avoid accidental nesting leads to a very granular and error prone usage pattern.
- The correct pairing of
BEGIN_RNG() and END_RNG() is not currently testable in pure C. There are likely mistakes.
The best solution here would be if the R interface called these functions before / after every igraph function, through Stimulus. The only disadvantage of this approach is that sometimes the call is unnecessary.
I would suggest adding an R-specific stimulus flag in R-functions.yaml to opt-out from usingGetRNGState() / PutRNGstate(). This way, if an igraph function is verified not to use the RNG in any way, these called can be skipped.
CC @krlmlr @ntamas
Currently, the C core uses the
BEGIN_RNG()andEND_RNG()macros to ensure thatGetRNGState()/PutRNGstate()are called. Managing this from the C core is quite difficult:GetRNGState()/PutRNGstate()pairs will lead to reduced randomness, as discussed at https://igraph.discourse.group/t/consistency-of-rng-begin-and-rng-end/641 Avoiding nesting is problematic because it limits function reuse.BEGIN_RNG()andEND_RNG()is not currently testable in pure C. There are likely mistakes.The best solution here would be if the R interface called these functions before / after every igraph function, through Stimulus. The only disadvantage of this approach is that sometimes the call is unnecessary.
I would suggest adding an R-specific stimulus flag in
R-functions.yamlto opt-out from usingGetRNGState()/PutRNGstate(). This way, if an igraph function is verified not to use the RNG in any way, these called can be skipped.CC @krlmlr @ntamas