Skip to content

set.seed() not working with function that uses future_lapply() #554

Answered by HenrikBengtsson
joelnitta asked this question in Q&A
Discussion options

You must be logged in to vote

ANSWER: Further investigation shows that this happens when the betapart package is loaded on the worker, which in turn loads snow, which generates a random port number when loaded.

Here's a minimal, reproducible example using only future:

library(future)
plan(cluster, workers = 1)
set.seed(42); value(future(runif(1L), seed = TRUE))
#> [1] 0.432844
set.seed(42); value(future(runif(1L), seed = TRUE))
#> [1] 0.432844
set.seed(42); value(future(runif(1L), seed = TRUE))
#> [1] 0.432844

all good so far, but if we load the snow package on our workers, which will only happens once per worker, then that will cause the RNG state to go forward at the first call;

set.seed(42); value(future(runif(1L), s…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@HenrikBengtsson
Comment options

Comment options

You must be logged in to vote
3 replies
@joelnitta
Comment options

@HenrikBengtsson
Comment options

@joelnitta
Comment options

Answer selected by joelnitta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants