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. Advertisements

  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. Advertisements

  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. Advertisements

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. Darren Clark

    Random NOt random?

    Darren Clark, Jun 24, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    597
    mikeb
    Jun 24, 2004
  2. Maziar Aflatoun

    Random not really random...

    Maziar Aflatoun, Aug 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    27,103
    Maziar Aflatoun
    Aug 5, 2004
  3. HumanJHawkins
    Replies:
    2
    Views:
    599
    peter koch
    Nov 30, 2006
  4. globalrev
    Replies:
    4
    Views:
    1,039
    Gabriel Genellina
    Apr 20, 2008
  5. Alex Untitled
    Replies:
    11
    Views:
    867
    Giampiero Zanchi
    Nov 16, 2009
  6. PerlFAQ Server

    FAQ 4.10 Why aren't my random numbers random?

    PerlFAQ Server, Feb 12, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    374
    PerlFAQ Server
    Feb 12, 2011
  7. PerlFAQ Server

    FAQ 4.10 Why aren't my random numbers random?

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