|
Hello
In my opinion, a better way to do what you need is to use one of the random number generator routines in "NUMERICAL RECIPIES": http://www.library.cornell.edu/nr/cbookcpdf.html
Scroll down to Ch. 7 in that page and you'll find a lot of algorithms that will be by far better you can come up using only your machine generator. You'll still need it, but the algorithms provide better "randomness" in your numbers and they are sorted by the way you need them to have certain statistical distributions. If you need them to have equal probabilities, then use the ran2 algorithm. This code is an implementation of it:
seed = 0;<br />
srand (time(NULL));<br />
rand();<br />
seed = rand();<br />
return ran2(seed);<br />
The return number is a uniform random deviate between 0 and 1. If you need integers just multiply your number as needed and take the integer.
Cheers
|
|
|
|
|
Hi All,
I'm trying to customize CEdit control to create dynamically growing and shrinking edit control by height. I'm stucked where I need to calculate the new height of the edit control, when the number of text exceeds the current limit. I 'm having the parameter which tells me the number of lines. I succeeded for the case of small fonts. I used the following formula:
nHeight = 13 * m_LineCount + 6;
This works fine.!!
But I would like to generalize this..! So Can Anyone help me to calculate the height for any font. even if the font is set small / large / custom.
It would be helpful for me if someone can help me to sort this out.!!
Thanks & Regards!
Rajesh
|
|
|
|
|
How about using
CFont *font = GetFont();
LOGFONT lf;
font->GetLogFont(&lf);
nHeight = lf.lfHeight * m_LineCount +6;
I think it will work.
Ritu Kwatra
|
|
|
|
|
Hi Ritu,
Thanks for the response. But it seems to be not working throughout.
This works fine for first few lines, after that for some case, the number of lines get incremented by double instead of single.
Expecting more ideas..
Thanks and regards!!
Rajesh
|
|
|
|
|
Hi Rajesh,
Are you sure that your linecount parameter is giving you correct value ?
If possible, mail me the piece of code.
Ritu Kwatra
|
|
|
|
|
I have a CString of 6 numbers how can i cast into one int variable so i can compare it with different numbers.
/\|-||\/|/\|)
|
|
|
|
|
int i;
CString str = "32";
sscanf(str, "%d", &i);
ASSERT(i == 32);
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
One more thing...
can i do this without the Assert coz i don't know the value of str in my program
thx anyway
/\|-||\/|/\|)
|
|
|
|
|
certainly, ASSERT() was just here to show you that aftrer treatment, the int contains the string's value...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
what about atoi[^]?
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
copy the string to char then use itoa
regards,
Rookie
|
|
|
|
|
sorry atoi
regards,
Rookie
|
|
|
|
|
Rookieee wrote:
int i;
CString str = "32";
sscanf(str, "%d", &i);ASSERT(i == 32);
int i;
CString str = "32";
sscanf(str, "%d", &i);ASSERT(i == 32);
watz wrong with this ^?
vivek
|
|
|
|
|
vivekuniq wrote:
Rookieee wrote:
int i;
CString str = "32";
sscanf(str, "%d", &i);ASSERT(i == 32);
watz wrong with this ^?
sorry but, this sample is mine, not Rookieee's...
and of course is works
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
What is the best way to store 1000000 serial number of 6 numbers?
What type should i use?
/\|-||\/|/\|)
|
|
|
|
|
sorry ?
what exactly is the question ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I can have at max 1000000 serial number. I need to store them in an array or somth knowing that the lenght of each serial number is always 6 numbers
/\|-||\/|/\|)
|
|
|
|
|
Halawlaws wrote:
1000000 serial number of 6 numbers
an array of 1,000,000 elements of 6 digit each? __int16 is too short so __int32.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
From the msdn website: "Note that the __int8 data type is synonymous with type char, __int16 is synonymous with type short, and __int32 is synonymous with type int". However, if you use MS VC++ on windows, the max integer value you can use with int is 32,767 if signed or twice that if unsigned. What you need is a long int that can take 2,147,483,647 or twice that if unsigned. If you need bigger values then __int64 works... partially... there seems to be a whole lot of things that are not supported for that data type in C++ but seem to work fine in C.
Cheers
|
|
|
|
|
__intN[^] are platform independent data types, they are synonims for the ANSI data types.
Cheers,
Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
I have a problem with printing.
When I print image it's very small on paper, but big on the screen.
So I decide to add code:
int logxPrn=GetDeviceCaps(hPrinterDC,LOGPIXELSX);
int logxScr=GetDeviceCaps(hDisplayDC,LOGPIXELSX);
But this values are same.Why?
int logxPrn=GetDeviceCaps(hPrinterDC,HORZRES);
int logxScr=GetDeviceCaps(hDisplayDC,HORZRES);
This values are too same!!!
Can Anyone Help me?
|
|
|
|
|
I had a similar problem that required me to use something like:
SetMapMode(hDC, MM_ISOTROPIC);
SetWindowOrg(hDC, bitmap_width / 2, bitmap_height / 2);
SetViewportOrg(hDC, GetDeviceCaps(hDC, HORZRES) / 2, GetDeviceCaps(hDC, VERTRES) / 2);
SetWindowExt(hDC, bitmap_width, bitmap_height);
SetViewportExt(hDC, GetDeviceCaps(hDC, HORZRES), GetDeviceCaps(hDC, VERTRES));
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
DavidCrow Can you explain me
How to use your code and how it works?
|
|
|
|
|
Are you using MFC?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|