Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:16:16+00:00 2026-06-10T15:16:16+00:00

I am writing random generation code in CUDA using the CURAND library. What I

  • 0

I am writing random generation code in CUDA using the CURAND library. What I read about random generation made me believe that if I use the same seed, I will get the same set of random numbers. But its not the case when I tested it. Please explain what am I doing wrong. I am pasting the code below for reference:


    curandGenerator_t rand_gen;  
    status = curandCreateGenerator (&rand_gen ,CURAND_RNG_PSEUDO_DEFAULT );  
    if(status != CURAND_STATUS_SUCCESS){  
            printf("Error encountered in generating handle\n");  
    }  
    status = curandSetPseudoRandomGeneratorSeed (rand_gen ,1234ULL);  
    if(status != CURAND_STATUS_SUCCESS){  
            printf("Error encountered in setting seed\n");  
    }  

    for(j=0; j<2; j++){  
            status = curandGenerate(rand_gen,a_d,N);  
            if(status != CURAND_STATUS_SUCCESS){  
                    printf("Error encountered in generating random numbers\n");  
             }

            cudaMemcpy ( a_h , a_d , N * sizeof(unsigned int),cudaMemcpyDeviceToHost);  
            for(i = 0; i < N; i++){  
                    printf("%d : %u\n",i,a_h[i]);  
            }
            printf("-----------%d----------------------\n",j);  
    }  
    status = curandDestroyGenerator(rand_gen);  
    if(status != CURAND_STATUS_SUCCESS){  
            printf("Error encountered in destroying handle\n");  
    }  

Output:

0 : 624778773
1 : 3522650202
2 : 2363946744
3 : 1266286439
4 : 3928747533
5 : 3732235839
6 : 1382638835
7 : 3362343509
8 : 48542993
9 : 1225999208
———–0———————-
0 : 3356973615
1 : 1004333919
2 : 2916556602
3 : 1213079917
4 : 2705410958
5 : 520650207
6 : 1860816870
7 : 1645310928
8 : 2205755199
9 : 1282999252
———–1———————-

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:16:18+00:00Added an answer on June 10, 2026 at 3:16 pm

    there is a notion of “state” of a pseudo-random generator. For example, Mersenne twister has a state of size about 1024 words while the the default one XORWOW has a state size just a several words (but it also has much smaller period).

    Whenever you call ‘setPseudoRandomGeneratorSeed’ you initialize the state of the generator. Then with subsequent calls to curandGenerate this state will be updated (i.e. to go from one random number to the next one, the state needs to be recomputed) and hence different parts of the random sequence will be generated.

    You might also experiment with the driver API – here curandInit() initializes the state for each thread which can be quite expensive. Then the subsequent calls to curand() or curandUniform() etc. will reuse this state. In fact each thread starts from different offset of a random sequence

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a code that performs a random scan over a set of 4
I am writing a game where the computer chooses a random number that a
Writing documentation in html requires some code examples. What to do with characters that
I'm writing a script that needs to be called at a random time during
For about a year I have been thinking about writing a program that writes
I am writing a multi-threaded Java program that generates lot of random numbers. Additional
I'm writing a bit of JavaScript code which should select a random item from
I am writing an email application using PyGTK. In almost every message that I
I'm writing a program that needs to read and write lots of data in
Possible Duplicate: random string generation - two generated one after another give same results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.