473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

random numbers with threads

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

Oct 17 '06 #1
3 1622
hande wrote:
but my program crashes in defining
the bounds for generating random numbers.
What program?
What about posting some code?
Oct 17 '06 #2

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);
}

Oct 17 '06 #3
hande" <hc*****@gmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
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.
Oct 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
21
by: Marc Dansereau | last post by:
Hi all I am new to this forum and to the c programming language. If I understand, the random() function in C return numbers that follow a uniform distribution U(0,1). Can somebody know how to...
5
by: user | last post by:
Hello i call it in almost same time (from two different threads): Random rand = new Random(); id=rand.Next(65535); and i often receive the same results. Is it possible ? How windows count this...
11
by: Mark Rae | last post by:
Hi, My R&D department has asked me to look at threading in a Web Service written in C#, so I came up with the following code: using System; using System.ComponentModel; using...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
6
by: D. Patrick | last post by:
I have a multi-threaded app that needs to generate random 8 digit numbers. I'm using VB.NET 2.0. The problem is that >1 request for a random number can occur in the same millisecond. I can't...
2
by: HumanJHawkins | last post by:
I wrote this question a little differently in the MFC group since it is a bit of a different environment than pure C++, but I hope you will forgive the similarities if anyone is reading both...
41
by: Zytan | last post by:
Anyone do any tests on it? I would assume it has improved since C's rand(), but who knows. For some reason, and it could just be coincidence, I seem to see patterns. But even a crappy rand()...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.