Skip to content

GetRNGState() / PutRNGstate() should be handled by the R interface instead of the C core #1131

@szhorvat

Description

@szhorvat

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions