# Generating Random Number from inside Kernel

**URL:** <https://discourse.julialang.org/t/generating-random-number-from-inside-kernel/8071>\
**Category:** GPU\
**Created:** [December 30, 2017, 9:19am UTC](https://discourse.julialang.org/t/generating-random-number-from-inside-kernel/8071 "2017-12-30T09:19:19Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [December 30, 2017, 1:26pm UTC](https://discourse.julialang.org/t/generating-random-number-from-inside-kernel/8071/5 "2017-12-30T13:26:23Z")

</div>

Just use the one in GPUArrays, it should work perfectly fine with CLArrays && CuArrays!

Here is an example of how you can use it:

> [@Saving values from GPU during Euler stepping in ODE](https://discourse.julialang.org/t/saving-values-from-gpu-during-euler-stepping-in-ode/7406/17):
>
> Okay I got it a bit faster: Initial version: 2.363006s 1.0s → Insert forgotten points (meaning only partially fused kernels, and tmp allocations) 0.7s → using sum(x) instead of sum(x, 1), possibly doesn’t generalize anymore? But the current version was 1D anyways 0.4s → moving everything into one gpu kernel final version: function clstep!(state, randstate, ratesum, kappa, y\_current, rates, dt) i = @linearidx(y\_current, state) yi = y\_current[i] # create tmp variables to not needles…

I should have a look if we can integrate xorshift as well… Looks a bit simpler then what I ported!

---

_[View the full topic](https://discourse.julialang.org/t/generating-random-number-from-inside-kernel/8071)._
