How to control the random number generation when using a parfor loop
Show older comments
When I want to repeat my code with the same results, I fix the seed in the beginning of the code. Say: rng(100) I can then generate a random vector: say R = rand(100,1). The result is the same every time I run the code.
Now, instead of generating a random vector of dimension 100 at once, I would like to parallelize my code using parfor and 5 workers. Each worker should work with a subvector: Worker one should work with R(1:20) (it has to generate it first since I do not want to save the whole thing before starting parfor), worker two works with R(21:40).. worker 5 works with R(81:100).
How to control the generation of these subvectors inside each parfor loop, such that the resulting vector R is the same as If I generated it by the command
rng(100)
R = rand(100,1)?
Accepted Answer
More Answers (0)
Categories
Find more on Random Number Generation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!