Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Does random_sample() exist?
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HazySmoke)345




PostPosted: Sun Aug 05, 2007 7:51 pm   Post subject: Does random_sample() exist?

According to what http://cppreference.com/cppalgorithm/random_sample.html has to say, random_sample() can be found under the <algorithm> header, so I assume that the following code would work:
code:
#include <algorithm>
using namespace std;

int main(){
        int a[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
        int b[15], c;
        c = min(1,2);
        random_sample(a,a+15,b,b+15);
return 0;}

Unfortunately, it didn't. The compiler gave me this message:

testing.cpp: In function `int main()':
testing.cpp:8: error: `random_sample' undeclared (first use this function)
testing.cpp:8: error: (Each undeclared identifier is reported only once for each function it appears in.)

I'm sure that I've installed my compiler properly because I've always beeing using it. Also, the min() function, which is also part of <algorithm>, didn't cause any error messages.

So, is the reference guide wrong? Or is the random_sample under a namespace other than std?
Sponsor
Sponsor
Sponsor
sponsor
rdrake




PostPosted: Sun Aug 05, 2007 7:53 pm   Post subject: RE:Does random_sample() exist?

Potential solution.
wtd




PostPosted: Sun Aug 05, 2007 10:43 pm   Post subject: RE:Does random_sample() exist?

Or just:

code:
#include <algorithm>

using namespace std;

int main()
{
   int a[] = { 1,  2,  3,  4,  5,
               6,  7,  8,  9, 10,
              11, 12, 13, 14, 15};
   int b[15]
   int c = min(1, 2);

   copy(a, a + 15, b);
   random_shuffle(b, b + 15);
}
HazySmoke)345




PostPosted: Tue Aug 07, 2007 7:36 pm   Post subject: Re: Does random_sample() exist?

Thanks rdrake and wtd, both solutions work. 8 bits each.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: