Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Sample without ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 45774 of 45898
Post > Topic >>

Sample without replacement+intersect

by Francogrex <franco@[EMAIL PROTECTED] > May 6, 2008 at 06:23 AM

Hi, I'm trying to sample without replacement some numbers (xons:70
values out of 1 to 200 and xEPS1cover:150 values out of 1 to 200).
Then I'm trying to intersect both samples to see how many are in
common. I have tried to write the code below, but I cannot seem to
sample without replacement (there are recurrent numbers within the
same sample, I don't want that) and I cannot either find the exact
intersection between the two samples. Can anyone please help or give
some hints. Thanks

#include <iostream>
#include <fstream>
using namespace std;

int main(){
ofstream osdis("dis.txt");
ofstream oscover("cover.txt");
srand(10);
int Ntot=200;
int Nons=70;
int i=0,j=0,r=0,t=0;
int xtot[200];
int xons[Ntot];
for (int i = 0; i < Ntot; i++){
xtot[i] = i;
}
for (int i = 0; i < Nons; i++)  {
r = rand()%Ntot + 0;
t = xtot[r];
xtot[r] = xtot[i];
xons[i] = t;
}
int NEPS1cover=150;
int xEPS1cover[NEPS1cover];
for (int i = 0; i < NEPS1cover; i++)  {
r = rand()%Ntot + 0;
t = xtot[r];
xtot[r] = xtot[i];
xEPS1cover[i] = t;
}
int R=0,u=0;
int xEPS1expected[NEPS1cover];
while(u<Nons){
int v=0;
while (v<NEPS1cover){
cout<<"dis: "<<xons[u]<<"\n";
cout<<"cover: "<<xEPS1cover[v]<<"\n";
if (xons[u]==xEPS1cover[v]){
printf("YES\n");
R=R+1;
}
v=v+1;
}
u=u+1;
}
for (j=0;j<Nons;j++) osdis<<xons[j]<<"\n";
for (i=0;i<NEPS1cover;i++) oscover<<xEPS1cover[i]<<"\n";
cout<<"R :"<<R<<"\n";
system("PAUSE");
return 0;
}




 4 Posts in Topic:
Sample without replacement+intersect
Francogrex <franco@[EM  2008-05-06 06:23:20 
Re: Sample without replacement+intersect
Christopher <cpisz@[EM  2008-05-06 12:53:30 
Re: Sample without replacement+intersect
Jerry Coffin <jcoffin@  2008-05-06 23:25:36 
Re: Sample without replacement+intersect
Lionel B <me@[EMAIL PR  2008-05-07 08:58:57 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 0:32:39 CDT 2008.