|
to not to produce
if(r<a)
else if(r="">=A && r<b)
else if(r="">=B && r
|
|
|
|
|
Are you talking about this?
(rand()%MAXRAND)%MAXVAL
Well,... It's the same of:
rand()%MAXVAL
Have a nice code day
|
|
|
|
|
I wanted to know if say in the case of MAXVAL=4 rand()%MAXVAL will result in spliting our 0...MAXRAND into:
rand range 0...15:
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
rand()%MAXVAL range:
0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3
this looks as we splitted our 0..MAXRAND range to adjasent quartets of 0,1,2,3 any number from 0..MAXRAND will fal into this range
but if the division of 0...15
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
to the sequence:
0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3
in first case rand val 6 will result in value of 2
in second 6 will result in 1
9ine
|
|
|
|
|
OK, I understand what you mean,
but we are talking about random numbers: so why we have to look how the algorithm are generating the numbers, and the numbers correspondances or order?
You want numbers from 0 to 3? well... use rand()%4 .
And don't put your eyes on how it works: the importatest think is that it works!
If you want that the distribution of the numbers remains the same you have to use something more complex (and slower) like this:
int((double(rand())/MAXINT)*MAXVALUE)
to get a number from 0 to MAXVALUE-1 related to the entire output range of rand()
but rand() generate numbers on an uniformally distribution, so nothing is changing between the different methods.
Hope it helps.
Have a nice code day
|
|
|
|
|
yes exactly uniform distribution.
we can do this by making array of indices:
0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,... N, N=MAXRAND
so the rand() value will be the index to array, but it needs the array, and time consuming, and if we change MAXVAL often it needs array recomposed etc.
but with int((double(rand())/MAXINT)*MAXVALUE) we also need to use smart rounding as int() round 3.9 and 3.1 to 3, which will inlude more computation
apparantly rand()%MAXINT will be the best choice
9ine
|
|
|
|
|
hai to all
i have a problem in retieving a registry key value.for this i have used
RegNotifyChangeKeyValue function which helps to identify which key has got changed.
but now my problem is what is the return value .and what does it represent.and how can i use the return value for further processing.since i have to develop an application which monitors any selected registry key
can any one help this by giving an example
|
|
|
|
|
Per MSDN:
fAsynchronous
[in] Specifies a flag that indicates how the function reports changes. If this parameter is TRUE, the function returns immediately and reports changes by signaling the specified event. When this parameter is FALSE, the function does not return until a change has occurred.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
|
hi
I want to check the privileges given for a specific user(in WinXP).I had a look at LookupAccountName() but is just retrieves the SID.
But I want to check
1)Whether the user has sufficient privileges(like Registry Privileges or Write Privileges...) over the system or not.
2)Whether the user belongs to particular domain (though i think LookupAccountName() Would suffice for this )
Any Sample Code or Links would do fine..
Thanx in advance
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
-- modified at 7:39 Tuesday 18th April, 2006
|
|
|
|
|
QuickDeveloper wrote: 1)Whether the user has sufficient privileges(like Registry Privileges or Write Privileges...) over the system or not.
Check out LookupPrivilegeValue() .
QuickDeveloper wrote: 2)Whether the user belongs to particular domain (though i think LookupAccountName() Would suffice for this )
Use NetWkstaUserGetInfo() .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi!
I want to have an array which holds of 2 different datatypes. Like
1 - > (2, true)
2 - > (4, false)
.....
Where is the best way to store this, Im looking on std::vector and std::map
|
|
|
|
|
lorey wrote: 1 - > (2, true)
2 - > (4, false)
What does that mean ??
And what are the 2 different datatypes ?
Anyway, how do you want to store this data in one single array if the types are different ? When retrieving the data, how can you tell what type of data it is ?
|
|
|
|
|
1 - > (x, y)
2 - > (x, y)
3 - > (x, y)
The 1 to 3 is just a counter.
the x will always hold integer value.
the y will always hold bool value.
|
|
|
|
|
Ok, your explanation wasn't very clear.
And why don't you simply make a structure that will pack these two vales together ? And then you use a vector of these struct.
Something like:
stuct MyStruct
{
int x;
bool y;
};
std::vector<MyStruct> MyArray;
|
|
|
|
|
|
For two values, a std::pair would probably suffice
std::vector<std::pair<int, bool> > MyArray;
...
MyArry.push_back(std::make_pair(int_value, bool_value));
The Rob Blog Google Talk: robert.caldecott
|
|
|
|
|
|
I build a MDI application, it contains 5 views. What is way to get information for order of view (view 1 is above view 2, view 2 is above view 3, ...).
-----------------
conglt
|
|
|
|
|
Hi,
U can get the view position by following.
this can be get from document class,
CUrDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
POSITION pos = pDoc->GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = pDoc->GetNextView(pos);
}
pos is position which u can type cast to integer.
Parthi.
|
|
|
|
|
thanks
-----------------
conglt
|
|
|
|
|
hai,
iam getting a small problem with dialogs.when ever a dialog is displayed and when ENTER or ESC key is pressed then the dialog is terminating.so plz help me to sort out this problem.
sathish
|
|
|
|
|
You can override 2 function OnOK() (for ENTER) and OnCancel (for ESC). In override function, you don't call base function from class CDialog
Example:
void CMyDialog::OnOK()
{
//CDialog::OnOK();
}
-----------------
conglt
|
|
|
|
|
|
By default the enter key means IDOK and esc key means IDCANCEL commands. So avoid this you have to override the followings functions as...
void OnOK() { /* nothing to do */ }
void OnCancel() { /* nothing to do */ }
Try it...
- NS -
|
|
|
|
|
The Esc key is automatically mapped to the IDCANCEL command. So you can get over that by overriding the handler to create an empty function.
Your Enter key is probably calling the OnOK handler because your OK button has the default focus. Again you could override the IDOK handler and bypass the default action, but you should provide an alternative means of exiting yoru dialog (calling the CDialog::OnOk(), or EndDialog() functions), else your program will have no means of quitting.
I Dream of Absolute Zero
|
|
|
|
|