|
We can set the seed value for rand() function using srand(seed) , but how to set the maximum. I want to generate random numbers between 1 to 10. Using the mod(%) operator without setting max limit is one way, but is there any function for setting max limit?
Thanks & Regards,
Suman
|
|
|
|
|
There's not such a function.
|
|
|
|
|
Ok. Thanks for your help.
Best Regards,
Suman
|
|
|
|
|
I assume you’re using code like this:
int val = rand()%10 + 1;
This will not produce evenly distributed random numbers!
‘rand’ generates random numbers from 0 to ‘RAND_MAX’ (32767).
Below if a list of ranges, each range maps from 1 to 10 (e.g. 0->1, 1->2, ..., 10->1, 11->2, etc):
0-9 10-19 20-29 …. 32750-32759 32760-32767 (32769)
Note the last range is smaller than the rest! The number in brackets is the value we would have to use as the maximum to make it the same size.
Here’s a breakdown of the last range:
32760 -> 1
32761 -> 2
32762 -> 3
32763 -> 4
32764 -> 5
32765 -> 6
32766 -> 7
32767 -> 8
This means the numbers from 1-8 will be slightly more likely to occur than 9 and 10 because 1-8 appear in all ranges whereas 9 and 10 appear in all ranges except the last!
If I were you I'd use Boost's Random[^] library.
Steve
|
|
|
|
|
Hi, I'm just starting in C++ and i need help.
The code is simple and i was able to made this work in previous program but when i used it again to other program it has error.
My code is:
double d = atof(str);
Error;
"Cannot convert CString to const char*"
math.h and stdlib.h already included.
What seems to be wrong with my code?
Am i missing something? or
Is there other way to convert string to double or float?
|
|
|
|
|
Try this:
double d = wcstod(str, NULL);
Best Regards,
Suman
|
|
|
|
|
Thank you for your suggestion.
It worked. Thanks a lot.
Till next time.
|
|
|
|
|
You are welcome!!
Best Regards,
Suman
|
|
|
|
|
Hi again,
How about int, double or float to String?
I usually used String.Format function:
int d = 20;
float f = 120.56;
str.Format("%d, %f",d,f);
AfxMessageBox(str);
The same error appeared. "cannot convert"
Hoping for your comments.
Thank you.
|
|
|
|
|
TooShy2Talk wrote: How about int, double or float to String?
Do you mean int , double or float to "CString".
If not so, pls try CString.
There are functions like itoa(), atoi() etc to convert from int to string, and vice versa. Doing google search with "int to CString" will display many solutions.
I am sorry, I saw your post now only.
If you still need help, please post a new message, so that all people can see your question.
Best Regards,
Suman
-- modified at 11:57 Tuesday 11th September, 2007
|
|
|
|
|
It's jusk OK.
Thank you again.
|
|
|
|
|
I always use it like that and it works
CString str = "";
double d = XXXX; //Any value
str.Format (_T("%lf"), d);
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Hi everybody,
I've written a mfc application which uses dundas gauge controls (together with windows forms). Everything works fine in debug or release mode but when I try to install the software on a different machine (windows XP, freshly installed) the application don't even start. Actually the installation works fine but the software don't run. I've checked all dependencies with dependency walker and also included "DundasWinGauge.dll" in the setup project (VS2005 setup wizard). DotNet is installed on the target machine. If I exclude the dundas gauge control then the application also runs on the target machine.
Does anybody have an idea?
Best regards,
Frank.
|
|
|
|
|
By chance, do you need vcredist_x86.exe on the target machine?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I don't know. What is vcredist_x86.exe? It's my first mixed-mode setup project. Actually it's my first setup project at all.
|
|
|
|
|
Franken wrote: What is vcredist_x86.exe?
See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hm, this unfortunatly doesn't solve the problem I've installed vcredist_x86.exe on the target machine but the error still occurs.
|
|
|
|
|
Ok, could it be a (ActiveX) control that needs to be registered?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I use TeeChart as ActiveX Control but this doesn't seem to make problems. It is the only ActiveX control which I use. When I build the setup project with the ActiveX control and without the gauge control (dll) everything works fine. The gauge control don't have any ActiveX component.
|
|
|
|
|
|
I don't know wether the problem is due to the manifest file. I have know experience with mixed-mode setup projects. I just added the exe file to the setup wizard and when I compile the setup project it recognizes the dependency to the dundaswingauge.dll which is then added to the setup project. When I exclude the dundas gauge control from the project. The application runs fine also on the target machine. The dundaswingauge.dll doesn't show up in the manifest file. Might this be the problem?
Best regards,
Frank.
|
|
|
|
|
I'm using the Win32 API on WindowsXP with Visual Studio 2005 to create an application with toolbars. I am using imagelists assigned to these toolbars to manage their state. Previously, I was just using normal image list (TB_SETIMAGELIST) and a hot image list (TB_SETHOTIMAGELIST). In that code, I could press a button, and disable it. It would show as grayed out and pressed.
Now, I have added using disabled image lists (TB_SETDISABLEDIMAGELIST) which look much better. I can disable a button and it shows it as grayed out using my disabled image. I can press a button and it looks fine with my normal image. But if I press the button, followed by disabling the button, instead of getting a pressed button with my gray image, I get a somewhat pressed button (there is a different background color but its not "sunken" in), and my normal image is showing in color.
Is it possible when using disabled image lists to have them pressed too?
Thanks,
|
|
|
|
|
|
You are using Bloodshed C++ in the version given?
Then you should be able to add libws2_32.a to the list of libraries to link.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|