|
You're right. With a look at disassembly,I supposed a weird kind of optimization happend, but I was wrong : hence no initialization problem, maybe, in fact, that, as you suppose, his output function has flaws.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
dear all
actually i had finished this case, but i would like to brief this code, so after tried, but couldn't.the orignal code is here, anyone can brief it? thanks..
int main()
{
int number;
double a [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
double a2 [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
double a3 [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
double a4 [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
double a5 [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
double a6 [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
double a7 [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
double a8 [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
double a9 [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
double a10 [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
for (int number = 1; number <= 10; number ++)
{
cout << setw(4) << number << endl;
printArray(a);
}
number ++;
cout << setw(6) << "\na1:" << endl;
printArray(a1);
cout << endl;
cout << setw(6) << "\na2:" << endl;
printArray(a2);
cout << endl;
cout << setw(6) << "\na3:" << endl;
printArray(a3);
cout << endl;
cout << setw(6) << "\na4:" << endl;
printArray(a4);
cout << endl;
cout << setw(6) << "\na5:" << endl;
printArray(a5);
cout << endl;
cout << setw(6) << "\na6:" << endl;
printArray(a6);
cout << endl;
cout << setw(6) << "\na7:" << endl;
printArray(a7);
cout << endl;
cout << setw(6) << "\na8:" << endl;
printArray(a8);
cout << endl;
cout << setw(6) << "\na9:" << endl;
printArray(a9);
cout << endl;
cout << setw(6) << "\na10:" << endl;
printArray(a10);
cout << endl;
return 0;
}
void printArray(double a[3][4])
{
for ( int i =0; i< 3; i++)
{
for (int j = 0; j < 4; j++)
cout <<setw(10) << setprecision(6) << setiosflags(ios::fixed|ios::showpoint) << a[i][j] << setw(10) ;
cout << endl;
}
}
from above code, i can obtain 10 3x4 random real number matrix, but i need to brief it.
thanks a lot in advance
Li Zhiyuan
4/01/2008
|
|
|
|
|
li zhiyuan wrote: anyone can brief it?
double a[3][4];
double a2[3][4];
double a3[3][4];
...
initArray(a);
initArray(a2);
initArray(a3);
...
printArray(a);
printArray(a2);
printArray(a3);
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Perhaps maybe nicer with an array of matrices:
int main()
{
double [10][3][4];
int i, j, k;
for (i=0; i<10; i++)
for (j=0; j<3; j++)
for (k=0; k<4; k++)
a[i][j][k] = (double)rand()/RAND_MAX;
for (i=0; i<10; i++)
{
cout << "\na[" << i << "]:" << endl;
printArray(a[i]);
}
return 0;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
li zhiyuan wrote: printArray(a);
Your array a is being initialized correctly, so the problem lies within the printArray() function.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You should seed the random number generator before each retrieval of a random number.
I suggest to create a function which returns a random integer.
Note:
Functions such as time(NULL) or clock() have a high probability of seeding the generator with the same seed since your code will execute faster than the time quantum available to such functions.
Try something like the following:
double DblRand()
{
unsigned __int64 ui64Seed;
__asm
{
rdtsc;
mov dword ptr ui64Seed, eax;
mov dword ptr ui64Seed + 4, edx;
}
srand((unsigned int)ui64Seed + clock());
return (double)rand() / 32767;
}
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: You should seed the random number generator before each retrieval of a random number.
Actually this is not true.
You should seed random number generator only when you need to re-start the sequence from another point.
For instance, if you develop a card game using the random generator to shuffle the cards then maybe nice to restart the random number generator from a different point of the sequence on every new game.
Randor wrote: double DblRand()
{
unsigned __int64 ui64Seed;
__asm
{
rdtsc;
mov dword ptr ui64Seed, eax;
mov dword ptr ui64Seed + 4, edx;
}
srand((unsigned int)ui64Seed + clock());
return (double)rand() / 32767;
}
Are you sure that such a function satisfy random number generation better that random generator itself?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
CPallini wrote: Actually this is not true.
I think you are misunderstanding my suggestion. I am giving the author of the question a best-practice tip on secure number generation. I was not saying that the re-seeding was neccessary.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: I think you are misunderstanding my suggestion.
Maybe.
Randor wrote: I am giving the author of the question a best-practice tip on secure number generation.
Re-seeding the random number generator each time you need a random number is not a best-practice behaviour (at least IMHO )
Happy new year & best wishes to you.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
dear all
this is main function:
double a [3][4] = {{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767},{(double)rand()/32767,(double)rand()/32767,(double)rand()/32767,(double)rand()/32767}};
for (int number = 1; number <= 10; number ++)
{
cout << setw(4) << number << endl;
printArray(a);
}
number ++;
void printArray ( double a [3][4])
{
for ( int i =0; i< 3; i++)
{
for (int j = 0; j < 4; j++)
cout <<setw(10) << setprecision(6) << setiosflags(ios::fixed|ios::showpoint) << a[i][j] << setw(10) ;
cout << endl;
}
}
how can i get 10 3x4 matrix and the each value inside array a is random real number....thanks a lot.
Li Zhiyuan
4/01/2008
|
|
|
|
|
I read that answer and yes, I saw before that tutorial but it really could not help too much
I just want an opinion of someone who made a project with XPCOM components before and know how to start things up. Is there anybody....?
Thanks again
|
|
|
|
|
What in all creation is XPCOM?
Do you mean COM on Windows XP or is this some obscure and badly named technology that no one actually uses?
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
It's nothing obscure or old. View this:
http://www.mozilla.org/projects/xpcom/book/cxc/html/quicktour2.html#1003424
or this
http://www.iosart.com/firefox/xpcom/
|
|
|
|
|
Fine but you seem to have answered your own question. The instructions for constructing an XPCOM Dll in MSVC++ are here[^] on the page you posted a link to. What is it that you can't do?
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I did that project too and succeeded after 2 days to build it without errors and when testing the component on firefox it gives a bunch of errors
That's why I SAID that I need the help of someone who DID THIS BEFORE !!!
Thanks
|
|
|
|
|
That's fine, no need to shout, there clearly aren't a lot of XPCOM guru's here so I suggest you either post the specific errors and ask a specific question (It all looks like pretty standard C++ stuff so you might get some help) or look for a dedicated XPCOM developer community elsewhere. If there isn't one out there then my original comment about obscurity stands.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
cuesdean florin wrote: That's why I SAID that I need the help of someone who DID THIS BEFORE !!!
Just so you know, I voted you a one because you're RETARDED.
|
|
|
|
|
You should have posted the error codes / descriptions ...
Maxwell Chen
|
|
|
|
|
Hi all,
Look at the following lines.
char *tempBuff[1024];
unsigned int iReq;
I want to copy the tempBuff to another buffer, adding the iReq to in-front of the tempBuff. How it is possible.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Are you sure your buffer should contain 1024 char pointers?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Sorry it should be char tempBuff[1024]
I appreciate your help all the time...
Eranga
|
|
|
|
|
char tempBuff[1024];
unsigned int iReq;
char newBuff[1024 + sizeof(iReq)];
memcpy(newBuff, &iReq, sizeof(iReq));
memcpy(newBuff + sizeof(iReq), tempBuff, 1024);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
TO CPallini:
Then how to read the first four bytes out to form the int value?
<br />
char tempBuff[1024];<br />
unsigned int iReq;
char newBuff[1024 + sizeof(iReq)];<br />
memcpy(newBuff, &iReq, sizeof(iReq));<br />
memcpy(newBuff + sizeof(iReq), tempBuff, 1024);
Can this achieve?
<br />
int *iptr = &newBuff[0];<br />
int iTReq = *iptr;
|
|
|
|
|
fantasy1215 wrote: Can this achieve?
int *iptr = &newBuff[0];
int iTReq = *iptr;
Yes.
Maxwell Chen
|
|
|
|
|
The code is correct, provided you cast the pointer, i.e.
int *iptr = (int*) (&newBuff[0]);
int iTReq = *iptr;
you can also do directly
int iTReq = *((int*)(&newBuff[0]);
or
int iTReq = *((int*)newBuff);
Cheers
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|