In a cuda application, I need filling a matrix with random values in an interval between a and b.
I used a code already available on the net, using CURAND, but I can not modify it to produce values between a and b.
Code is as follows:
// Fill the array A(nr_rows_A, nr_cols_A) with random numbers on GPU
void GPU_fill_rand(float *A, int nr_rows_A, int nr_cols_A)
{
    // Create a pseudo-random number generator
    curandGenerator_t prng;
    curandCreateGenerator(&prng, CURAND_RNG_PSEUDO_XORWOW);
    // Set the seed for the random number generator using the system clock
    curandSetPseudoRandomGeneratorSeed(prng, (unsigned long long) clock());
    // Fill the array with random numbers on the device
    curandGenerateUniform(prng, A, nr_rows_A * nr_cols_A);
}
int main(void)
{
    // Variables declaration
    float   *hst_Mat ,
        *dev_Mat;
    int Height = 3 ;
    int Width  = 10 ;
    int vSize = Height*Width ;
    int mSize = sizeof(float)*vSize ;
    hst_Mat = (float *)malloc(mSize) ;
    cudaMalloc((void**)&dev_Mat, mSize) ;
    memset(hst_Mat, 0, mSize) ;
    cudaMemset(dev_Mat, 0, mSize) ;
    // Print initial matrix
    cout << " * Initial matrix : " << endl << "\t" ;
    for(int i=0 ;i<Height ; i++)
    {
        for(int j=0 ; j<Width ; j++)
            cout << "\t" << hst_Mat[i*Width+j] ;
        cout << endl << "\t" ;
    }
    cout << endl << endl ;
//
// Cuda kernel invoke
//
    // Initializing device state for random generator
    GPU_fill_rand(dev_Mat, Height, Width) ;
    // Retrieving data from device
    cudaMemcpy(hst_Mat, dev_Mat, mSize, cudaMemcpyDeviceToHost) ;
//
// Print result matrix
//
    cout << " * Result matrix : " << endl << "     " ;
    for(int i=0 ;i<Height ; i++)
    {
        for(int j=0 ; j<Width ; j++)
            cout << "   " << hst_Mat[i*Width+j] ;
        cout << endl << "     " ;
    }
    cout << endl << endl ;
    // FREE MEMORY
    free(hst_Mat) ;
    cudaFree(dev_Mat) ;
    system("pause") ;
    return 0;
}
But it generate a true random value in [0 and 1].
How to do this?
 
     
     
    