|
See Demo toolbar for OE
http://www.plugins-soft.com/demos.html
BUT this commercial source.
|
|
|
|
|
Hi I'm trying to do the following:
1) generate a random # from the array layer_array[]
2) swap the number generated with a negative number, to avoid repetition of that random #.
I'm not sure I'm correctly sampling from layer_array[]. And I'm definitely not implementing swap() correctly....how would i proceed?
Please help.
<br />
#include <cmath><br />
#include "stdafx.h"<br />
#include <ctime><br />
#include <cstdlib><br />
#include <algorithm><br />
#include <fstream><br />
#include <iostream><br />
#include <iomanip><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
const int size = 20;<br />
<br />
int layer_array[size]={0};<br />
<br />
for(int i=0; i<size; i++)<br />
layer_array[i]=i+1;<br />
<br />
srand((unsigned)time(0)); <br />
<br />
int random_integer[size] ={0};
<br />
for(int index=0; index<size; index++)<br />
{<br />
random_integer[index] = (rand()%size)+1; <br />
swap(&layer_array[index],&layer_array[index*-1]);
<br />
cout << random_integer[index] << endl; <br />
}<br />
<br />
return 0;<br />
}<br />
|
|
|
|
|
aaadetos wrote:
swap(&layer_array[index], &layer_array[index * -1]);//error c2664
I'm curious what you are expecting to swap with this. You typically don't dereference an array using a negative number.
By the very definition of random, uniqueness is not a quarantee. Therefore, you can't get a random number that is guaranteed to not repeat. If you do, then it is not random. However, if you are simply wanting a list of unique numbers returned to you in a pseudo-random order, that is a different beast altogether.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I'm curious too! According to the code presented, [index * -1] would result in an illegal array index value, except for index=0.
INTP
Every thing is relative...
|
|
|
|
|
you say you have a c2664 compiler error, ,but does it say exactly ?
C2664 is : 'function' : cannot convert parameter number from 'type1' to 'type2'
please tell the entiere error message, ,otherwise it doesn't mean anything for us...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
One way to obtain an array of random numbers with none repeating is as follows:
Since your random number is to be in the range 1-n, it is better to simply initialize an array of size n with the numbers 1-n:
for (int i = 0; i < size; i++)<br />
layer_array[i] = i + 1;
(BTW for peformance, don't initialize the array first with "{0}" since you are immediately initializing it one line later.)
Now, seed the random number and then go through the array again exchanging every value with the value at a randomly selected offset:
for (i = 0; i < size; i++)<br />
{<br />
int dst = rand() % size;<br />
<br />
int tmp = layer_array[i];<br />
layer_array[i] = layer_array[dst];<br />
layer_array[dst] = tmp;<br />
}
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi
I'm not sure what u mean:
(1) to fill an array with non-repeating random numbers
or (2) to shuffle array elements
From your code it looks more like 2. It also looks like the [Delete] was pushed here and there...
The technique of marking used elements is not good. If u had an array of 1M the last iteration would lots of time coz u'd repeat it lots of time till u hit the one out million left..
What u should do is this:
<br />
int i, new_array[size], old_array[size];<br />
<br />
for(i=0; i<size; i++)
init(old_array+i);<br />
<br />
for(i=0; size>0; i++) {<br />
new_array[i] = old_array[x=(rand()%size)];<br />
<br />
old_array[x] = old_array[--size];<br />
}<br />
HTH
Yakov
-- modified at 10:07 Thursday 27th October, 2005
|
|
|
|
|
I am new to the use of sockets, ports and client/server applications.
I have an application that will Connect to a proxy server (to allow for remote commands).
However if the server is temporarily lost (unexpectedly) how do I detect it returning?
My application continues to run but never re-Connects to the server.
Does the server notify me? if so how?
Should I use GetPeerName or can I continually try to Connect to an already connected port
I have a 2 minute timeout timer that I intend to use as a Connect retry control but I need to know when to start.
I am using Visual Studio 6 and VC++
|
|
|
|
|
cgb143 wrote: However if the server is temporarily lost (unexpectedly) how do I detect it returning?
If a socket connection is closed, you need to reinitiate it. On TCP/IP level there is no notification when another peer is back "online" after the connection is closed, you could try to reconnect in intervalls or work out a protocol where the server activly sends something (like a broadcast inside a LAN). Make sure you don't flood the network with wild/endless reconnect attempts, e.g. give up after the 10th reconnect attempt. Hope it helps.
|
|
|
|
|
i'm trying to implement a button that functions for example the way that the seek or pitchbend controls function on a cd player. that is, you press/'push' it and 'work starts getting done' and 'stops getting done' when/after you release the button.
the only way that i know and that works is to check mouse coordinates upon WM_LBUTTONDOWN/UP (since WM_COMMAND gets sent only after you press and depress a button) and compare them with the button position/recantgle and then take appropriate action... but that seems too complicated (calculating, storing & comparing coordinates), is there a simpler way ?
thnx
|
|
|
|
|
There are lots of button examples here.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
|
Anonymous wrote: i'm looking for a perhaps simpler/more efficient method (and with using just win32) ...
While only partially related, have you seen this?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: While only partially related, have you seen this?
hmm thanks for the link but i can't find the handling of WM_LMBUTTONDOWN (and checking if it's for the desired button) in the shown code of that example... am i blind or is it somehow hidden/already implemented by mfc ?
i found a different approach, explained here http://www.pluralsight.com/articlecontent/cpprep0797.htm[^]. it seems simpler and more logical but to implement it for this purpose the button control, that is it's window, should have it's own window procedure which i could then override to handle WM_LMBUTTONDOWN/UP messages... so my question is do even the buttons have a window procedure ?
although when i think about it this approach also isn't as straitforward as it looks, at least not for what i need to use it. in the new wnd procedure i would then have to call GetParent() and then send a message to the parent dialogbox which would then again have to be processed by the dialogbox procedure ...
in your opinion, which method is more efficient then ?
|
|
|
|
|
|
Hi
I am a student.When I do my homework,i encounter a problem.I can not get
the actual value in VisualC++.
The question is how to get 95.123 raised by 12.
Maybe I haven't explained my mean.Sorry about my poor English!
Thanx first!
-- modified at 1:49 Thursday 27th October, 2005
|
|
|
|
|
What are you speaking about ?? What means " 95.123 's 12th power " ?? And what are you trying to do exactly and what is the exact problem encoutered ?
Try to be more specific.
|
|
|
|
|
The question is how to get 95.123 raised by 12.
Maybe I haven't explained my means.Sorry about my poor English!
|
|
|
|
|
You can use the double pow(double,double); for that purpose. Don't forget to include math.h at the top of your file .
|
|
|
|
|
ShiningStarPxx wrote: The question is how to get 95.123 's 12th power.
Do you mean 95.12312 instead? Even using an unsigned long double , you'd get something like 5.4881562051773182e+023. You might could get a bit more precision by using the DECIMAL data type.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Thank you first!
But i can not catch your means.Would you like to explain it with a sample code.
|
|
|
|
|
#include <math.h>
#include <stdio.h>
void main( void )
{
double x = 2.0, y = 3.0, z;
z = pow( x, y );
printf( "%.1f to the power of %.1f is %.1f\n", x, y, z );
}
Output
2.0 to the power of 3.0 is 8.0
|
|
|
|
|
Oops sorry, the <'s and >'s got removed, the #include's should be
#include <math.h>
#include <stdio.h>
|
|
|
|
|
On paper, 95.12312 is 548815620517731830194541.89902534. However, that number is too big to fit in any type, including an unsigned long double . It would only give you something like 5.4881562051773182e+023 (which equates to 548815620517731820000000.0). Notice the loss of precision. A DECIMAL type may get you a bit more precision.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Hi,
I have an application working perfectly when compiled in the debug version with optimization off. But the release with optimization on/off and the debug version with optimization on crashes every now and then. Can someone tell me what can be the problem?
I have a places where i do the following :
Literal_Object *lit = (Literal_Object *)pt;
pt is an object Node_Object which is the base class of Literal_Object.
Can this be the cause of my problem?
Thanx in advance.
Mithin
|
|
|
|