Skip to content

Issue with random numbers and R calls from C++ #1013

@Enchufa2

Description

@Enchufa2

It may have something to do with #465, which was unresolved back in 2016:

Rcpp::cppFunction("bool comp(Function fun) { return runif(1)[0] > as<double>(fun()); }")
set.seed(1)
sum(replicate(1e3, comp(function() runif(1, 0, 1))))
# 0
sum(replicate(1e3, comp(function() runif(1, 0.0001, 0.9999))))
# 481

This is very odd. I'm not sure what's happening here. I've spent hours debugging a package of mine due to a very strange behaviour that has to do with this, but I finally managed to get this simple example that only involves Rcpp. I don't have much energy left today to investigate further. Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions