Skip to content

Correlated random numbers in nested loops #74

Open
@lbau7

Description

@lbau7

I saw this bug on future.apply's GitHub page [HB edit: futureverse/future.apply#108] and checked whether the same issue exists with dofuture-loops, since this is something that I used in an R-package that I'm currently developing. Is this the same bug or am I doing something wrong?

Describe the bug
When random numbers are generated in a nested loop using the %dofuture% adapter many random numbers appear several times

Reproduce example
library(doFuture)
plan(multisession, workers = 4)
foreach::foreach(i = 1:4,.combine = 'cbind') %dofuture% {
b <- foreach::foreach(j = 1:4) %dofuture% {
runif(1)
} %seed% TRUE
b
} %seed% TRUE

Expected behavior
Random numbers should be unique.

Session information
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8
[4] LC_NUMERIC=C LC_TIME=German_Germany.utf8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] doFuture_1.0.0 future_1.32.0 foreach_1.5.2

loaded via a namespace (and not attached):
[1] compiler_4.2.1 parallelly_1.35.0 parallel_4.2.1 tools_4.2.1 future.apply_1.10.0
[6] listenv_0.9.0 codetools_0.2-18 iterators_1.0.14 digest_0.6.31 globals_0.16.2

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