GPGPURAND generate random value,how to control its range?

Jul 17, 2013 at 9:42 AM
GPGPURAND gen = GPGPURAND.Create(gpu, curandRngType.CURAND_RNG_PSEUDO_DEFAULT );
                gpu.Synchronize();
                gen.SetPseudoRandomGeneratorSeed(SEED);
               gen.GenerateNormal(devData, 0, 1);
In GenerateNormal( par1 , par2, par3 ), If I want to get random value belong to (-1,1), how can I set par2 and par3 ?
Jul 17, 2013 at 10:04 AM
In a normal distribution, values range from -inf to +inf (otherwise it wouldn't be a normal), so I don't quite understand what you're trying to do
Jul 17, 2013 at 1:13 PM
class Program
{
    private const int RANDOM_NUMBERS = 20;
    private const int SEED = 1234;
    static void Main(string[] args)
    {
            float timer = 0;
            try
            {
                GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target);
                float[] devData = gpu.Allocate<float>(RANDOM_NUMBERS);
                uint[] devintData = gpu.Allocate<uint>(RANDOM_NUMBERS);
                float[] hostData = new float[RANDOM_NUMBERS];
                uint[] hostintData = new uint[RANDOM_NUMBERS];
                GPGPURAND gen = GPGPURAND.Create(gpu, curandRngType.CURAND_RNG_PSEUDO_DEFAULT );
                gpu.Synchronize();
                gpu.StartTimer();
                gen.SetPseudoRandomGeneratorSeed(SEED);
               gen.GenerateNormal(devData, 0, 5);
                 //gen.GenerateUniform(devData);
                gpu.Synchronize();
                timer = gpu.StopTimer();
                gpu.CopyFromDevice(devData, hostData);
                gen.Dispose();
                gpu.FreeAll();
                for (int i = 0; i < 20; i++)
                {
                    Console.WriteLine("   {0}  ", hostData[i]);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex);
            }           
    }
}
the result is:
3.90487
-9.007889
-1.404244
2.817732
-5.056665
2.070195
7.291627
-2.810681
-0.742882
-1.975927
-0.02074005
-2.649791
7.250984
2.02379
2.448532
2.498995
-3.685561
-14.51048
7.507629
2.513937

I have seen this problem in the web, In this problem, I want to konw, if I want get random value from -2 to 2, like(-0.1192, 0.1223, 1.5000, -1.9999, 0.8802,........),all the value in the range (-2,2). I don't know If I should use the gen.GenerateNormal() function, should I used another function?
If you can answer for me, I would be very grateful!
Jul 17, 2013 at 1:15 PM
class Program
{
private const int RANDOM_NUMBERS = 20;
private const int SEED = 1234;
static void Main(string[] args)
{
        float timer = 0;
        try
        {
            GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target);
            float[] devData = gpu.Allocate<float>(RANDOM_NUMBERS);
            uint[] devintData = gpu.Allocate<uint>(RANDOM_NUMBERS);
            float[] hostData = new float[RANDOM_NUMBERS];
            uint[] hostintData = new uint[RANDOM_NUMBERS];
            GPGPURAND gen = GPGPURAND.Create(gpu, curandRngType.CURAND_RNG_PSEUDO_DEFAULT );
            gpu.Synchronize();
            gpu.StartTimer();
            gen.SetPseudoRandomGeneratorSeed(SEED);
           gen.GenerateNormal(devData, 0, 5);
             //gen.GenerateUniform(devData);
            gpu.Synchronize();
            timer = gpu.StopTimer();
            gpu.CopyFromDevice(devData, hostData);
            gen.Dispose();
            gpu.FreeAll();
            for (int i = 0; i < 20; i++)
            {
                Console.WriteLine("   {0}  ", hostData[i]);
            }
        }
        catch (System.Exception ex)
        {
            Console.WriteLine(ex);
        }           
}
}
the result is:
3.90487
-9.007889
-1.404244
2.817732
-5.056665
2.070195
7.291627
-2.810681
-0.742882
-1.975927
-0.02074005
-2.649791
7.250984
2.02379
2.448532
2.498995
-3.685561
-14.51048
7.507629
2.513937

I have seen this problem in the web, In this problem, I want to konw, if I want get random value from -2 to 2, like(-0.1192, 0.1223, 1.5000, -1.9999, 0.8802,........),all the value in the range (-2,2). I don't know If I should use the gen.GenerateNormal() function, should I used another function?
If you can answer for me, I would be very grateful!
Jul 17, 2013 at 2:12 PM
Edited Jul 17, 2013 at 2:13 PM
I assume you want a uniform distribution. Call this
        gen.GenerateUniform(devData);
instead of
        gen.GenerateNormal(devData, 0, 5);
and then multiply by 4 and subtract 2 to each element in the array. This will get you values between -2 and 2
or multiply by 2 and subtract 1 to each element in the array to get you values between -1 and 1
Jul 18, 2013 at 2:06 AM
OK, Thank you very much!