# \[Question\] Distributions.jl with CUDA

**URL:** https://discourse.julialang.org/t/question-distributions-jl-with-cuda/47707
**Category:** Statistics
**Tags:** question, cuda, distributions
**Created:** [October 3, 2020, 9:21pm UTC](https://discourse.julialang.org/t/question-distributions-jl-with-cuda/47707 "2020-10-03T21:21:07Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![sheevy](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sheevy](https://discourse.julialang.org/u/sheevy)
#### Post date: [October 3, 2020, 9:21pm UTC](https://discourse.julialang.org/t/question-distributions-jl-with-cuda/47707/1 "2020-10-03T21:21:07Z")

</div>

Hi,  
I’m writing a program which I wish could easily work both cpu and gpu, similarly to what one can achieve in Flux with cpu and gpu functions. I was under impression that different Julia packages compose well, so I expected the following to work:

```julia
using CUDA
using Distributions

rand(Random.GLOBAL_RNG, LogNormal(1.0, 1.0), 10)
rand(CUDA.CURAND.default_rng(), LogNormal(1.0, 1.0), 10)

```

I could then control which random number generator to use via a flag which would in turn dispatach to CPU or GPU appropriately. However the code above fails in the last line.

The question I have is whether I’m doing something non idiomatic and there’s an easy way to make this work. I was hoping in Julia I can avoid writing a boilerplate code, like so:

```julia
function rand_logn(n, mean, stddev)
    if use_gpu
        return CUDA.rand_logn(n, mean=mean, stddev=stddev)
    else
        return rand(LogNormal(mean, stddev), n)
    end
end

```
