
-----------------------------------
HazySmoke)345
Sun Aug 05, 2007 7:51 pm

Does random_sample() exist?
-----------------------------------
According to what http://cppreference.com/cppalgorithm/random_sample.html has to say, random_sample() can be found under the  header, so I assume that the following code would work:
#include 
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 , didn't cause any error messages.

So, is the reference guide wrong? Or is the random_sample under a namespace other than std?

-----------------------------------
rdrake
Sun Aug 05, 2007 7:53 pm

RE:Does random_sample() exist?
-----------------------------------
[url=http://gcc.gnu.org/ml/gcc/2002-08/msg01159.html]Potential solution.

-----------------------------------
wtd
Sun Aug 05, 2007 10:43 pm

RE:Does random_sample() exist?
-----------------------------------
Or just:

#include 

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
Tue Aug 07, 2007 7:36 pm

Re: Does random_sample() exist?
-----------------------------------
Thanks rdrake and wtd, both solutions work. 8 bits each.
