random numbers with threads

Discussion in 'C++' started by hande, Oct 17, 2006.

  1. hande

    hande Guest

    Hi, I wrote a program with two threads playing a number guessing game.
    one thread pick a number the other try to guess it. Also first thread
    say try a lower or higher number. but my program crashes in defining
    the bounds for generating random numbers.
    For instance the first thread pick 35
    the other say 19. he should pick a number bigger than 19. for now
    that's ok. now second thread say 60. then first thread say lower
    number. but my second thread is not like that. how i can define that
    borders?

    thanks a lot
    hande, Oct 17, 2006
    #1
    1. Advertising

  2. hande

    Martin Steen Guest

    hande wrote:
    > but my program crashes in defining
    > the bounds for generating random numbers.


    What program?
    What about posting some code?
    Martin Steen, Oct 17, 2006
    #2
    1. Advertising

  3. hande

    hande Guest

    Martin Steen wrote:
    > hande wrote:
    > > but my program crashes in defining
    > > the bounds for generating random numbers.

    >
    > What program?
    > What about posting some code?



    else if(num<gnum)
    {
    gnum=rand()%gnum;
    temp2=gnum;
    cout<<"Thread2: "<<gnum<<endl;
    // pthread_mutex_unlock(&myMutex);
    }
    else if(num>gnum)
    {
    gnum=rand()%(100-gnum);
    cout<<"Thread2: "<<gnum<<endl;
    //pthread_mutex_unlock(&myMutex);
    }
    hande, Oct 17, 2006
    #3
  4. hande

    Jim Langston Guest

    hande" <> wrote in message
    news:...
    > Hi, I wrote a program with two threads playing a number guessing game.
    > one thread pick a number the other try to guess it. Also first thread
    > say try a lower or higher number. but my program crashes in defining
    > the bounds for generating random numbers.
    > For instance the first thread pick 35
    > the other say 19. he should pick a number bigger than 19. for now
    > that's ok. now second thread say 60. then first thread say lower
    > number. but my second thread is not like that. how i can define that
    > borders?
    >
    > thanks a lot


    First, try your program without the threads. See if it works that way. If
    it does, then it's a threading issue and post some code at:
    comp.programming.threads that is small enough to show the problem.

    If it does not without the threads, it's a C++ error, post the smallest code
    here that compiles that wll show the error.
    Jim Langston, Oct 17, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. globalrev
    Replies:
    4
    Views:
    741
    Gabriel Genellina
    Apr 20, 2008
  2. Alex Untitled
    Replies:
    11
    Views:
    648
    Giampiero Zanchi
    Nov 16, 2009
  3. PerlFAQ Server

    FAQ 4.10 Why aren't my random numbers random?

    PerlFAQ Server, Feb 12, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    210
    PerlFAQ Server
    Feb 12, 2011
  4. PerlFAQ Server

    FAQ 4.10 Why aren't my random numbers random?

    PerlFAQ Server, Apr 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    238
    PerlFAQ Server
    Apr 27, 2011
  5. VK
    Replies:
    15
    Views:
    1,115
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page