Does random_sample() exist?
Author |
Message |
HazySmoke)345
![](http://i10.photobucket.com/albums/a121/HazySmoke/clubps2.jpg)
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
rdrake
![](http://compsci.ca/v3/uploads/user_avatars/113417932472fc6c9cd916.png)
|
Posted: Sun Aug 05, 2007 7:53 pm Post subject: RE:Does random_sample() exist? |
|
|
Potential solution. |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: 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);
} |
|
|
|
|
|
![](images/spacer.gif) |
HazySmoke)345
![](http://i10.photobucket.com/albums/a121/HazySmoke/clubps2.jpg)
|
Posted: Tue Aug 07, 2007 7:36 pm Post subject: Re: Does random_sample() exist? |
|
|
Thanks rdrake and wtd, both solutions work. 8 bits each. |
|
|
|
|
![](images/spacer.gif) |
|
|