# Generating matrix random variables in Multi-Threaded mode with Distributions

**URL:** <https://discourse.julialang.org/t/generating-matrix-random-variables-in-multi-threaded-mode-with-distributions/22802>\
**Category:** General Usage\
**Tags:** package\
**Created:** [April 5, 2019, 3:16pm UTC](https://discourse.julialang.org/t/generating-matrix-random-variables-in-multi-threaded-mode-with-distributions/22802 "2019-04-05T15:16:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krenova](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@krenova](https://discourse.julialang.org/u/krenova)\
**Post date:** [April 5, 2019, 3:16pm UTC](https://discourse.julialang.org/t/generating-matrix-random-variables-in-multi-threaded-mode-with-distributions/22802/1 "2019-04-05T15:16:58Z")

</div>

I now understand (from [Multi-threading](https://discourse.julialang.org/t/multi-threading/22708)) that I need to generate random seeds for each thread to avoid race conditions if I wish to speed up the generation of independent random variables. One good and straightforward way of doing this is the following code snippet from [Parallel Computing · The Julia Language](https://docs.julialang.org/en/v1/manual/parallel-computing/index.html)

```julia
using Random
import Future

rseed = let m = MersenneTwister(1)
    [m; accumulate(Future.randjump, fill(big(10)^20, Threads.nthreads()-1), init=m)]
end;

```

The problem is that I wish to generate Inverse Wishart random variables from the Distributions package but find that I’m unable to do so because of the way the related `InverseWishart()` function and its extensions are defined. Executing

```julia
rand( rseed[1], InverseWishart( 5, [1.0 0; 0 1] ) )

```

will return

```julia
ERROR: ArgumentError: Sampler for this object is not defined

```

Wonder if anyone would be able to guide me to a workaround? I tried looking the base codes of the function `InverseWishart` from [Distributions.jl/inversewishart.jl at b05da33f63421994868b3ec57ff57fb6a7b36d7e · JuliaStats/Distributions.jl · GitHub](https://github.com/JuliaStats/Distributions.jl/blob/b05da33f63421994868b3ec57ff57fb6a7b36d7e/src/matrix/inversewishart.jl)  
to try and work something out but struggled to understand and meaningfully manipulate their definitions to my favour.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [April 5, 2019, 11:59pm UTC](https://discourse.julialang.org/t/generating-matrix-random-variables-in-multi-threaded-mode-with-distributions/22802/2 "2019-04-05T23:59:11Z")

</div>

This works for me on Julia `v1.0.3` and `v1.1.0` with `Distributions v0.17.0`.

What versions are you using?

---

<div class="post-metadata">

**Author:** ![krenova](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@krenova](https://discourse.julialang.org/u/krenova)\
**Post date:** [April 6, 2019, 3:17am UTC](https://discourse.julialang.org/t/generating-matrix-random-variables-in-multi-threaded-mode-with-distributions/22802/3 "2019-04-06T03:17:26Z")

</div>

It does work now @greg_plowman.

I was using `Distributions v0.16.4`.

Thanks for the heads up.
