diff --git a/doc/source/array.rst b/doc/source/array.rst
index bd9ce90c43cb8b93af0dbff3f42c9f873616828d..e49f8305e28bd56ee2a980677cbda05a7f508c80 100644
--- a/doc/source/array.rst
+++ b/doc/source/array.rst
@@ -418,6 +418,10 @@ Generating Arrays of Random Numbers
Return an array of `shape` filled with random values of `dtype`
in the range [0,1).
+.. function:: fill_rand(result, queue=None)
+
+ Fill *result* with random values of `dtype` in the range [0,1).
+
PyOpenCL now includes and uses the `RANLUXCL random number generator
`_ by Ivar Ursin Nikolaisen. In
addition to being usable through the convenience functions above, it is
diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py
index 7710bc60e99e026e070b6e09714649847821e627..efa39f2e89edbcd81f420d49e676d475dfc5b2ae 100644
--- a/pyopencl/clrandom.py
+++ b/pyopencl/clrandom.py
@@ -27,7 +27,7 @@ class RanluxGenerator(object):
self.use_legacy_init = use_legacy_init
self.max_work_items = max_work_items
- prg = cl.Program(queue.context, """
+ src = """
%s
#include
@@ -36,7 +36,8 @@ class RanluxGenerator(object):
{
ranluxcl_initialization(seeds, ranluxcltab);
}
- """ % self.generate_settings_defines()).build()
+ """ % self.generate_settings_defines()
+ prg = cl.Program(queue.context, src).build()
self.state = cl_array.empty(queue, (num_work_items, 112), dtype=np.uint8)
prg.init_ranlux(queue, (num_work_items,), None, np.uint32(seed),
@@ -218,12 +219,14 @@ def _get_generator(queue):
-@cl_array.elwise_kernel_runner
-def _rand(output, seed):
- return get_rand_kernel(output.context, output.dtype)
+def fill_rand(result, queue=None):
+ if queue is None:
+ queue = result.queue
+ gen = _get_generator(queue)
+ gen.fill_uniform(result)
+
+
-def fill_rand(result):
- _rand(result, np.random.randint(2**31-1))
def rand(*args, **kwargs):
def inner_rand(queue, shape, dtype):