Skip to content

Random numbers in OpenCL

Similarly to Noise functions, we also have random number generators within the random.h file.

You can import it same way as our noise patterns

OpenCL
#import "random.h"
static float VEXrandom_1_1(float x)
static float2 VEXrandom_1_2(float x)
static float3 VEXrandom_1_3(float x)
static float4 VEXrandom_1_4(float x)
static float VEXrandom_2_1(float x, float y)
static float2 VEXrandom_2_2(float x, float y)
static float3 VEXrandom_2_3(float x, float y)
static float4 VEXrandom_2_4(float x, float y)
static float VEXrandom_3_1(float x, float y, float z)
static float2 VEXrandom_3_2(float x, float y, float z)
static float3 VEXrandom_3_3(float x, float y, float z)
static float4 VEXrandom_3_4(float x, float y, float z)
static float VEXrandom_4_1(float x, float y, float z, float w)
static float2 VEXrandom_4_2(float x, float y, float z, float w)
static float3 VEXrandom_4_3(float x, float y, float z, float w)
static float4 VEXrandom_4_4(float x, float y, float z, float w)

Description:

This set of functions mimics VEX random() function. Depending on your scenario, you may want to input float-float4 and output float-float4

side note:

When using VEXrandom function, you could be thinking that it would create a white noise when passing lets say @P. But actually, as its vex equivalent, this function converts the floating point argument to an integer seed.

opencl-random-1
To get that "white noise" effect, you may want to either scale your @P,@uv or use something like @iy @iy (buffer integer index)
opencl-random-1