Possible Duplicate:
How exactly should I implement a shuffle or random-number algorithm for an array to display quotes in random order?
I have a small array that I need the values to be randomly shuffled around within the array. I can do this in python using random.shuffle(), but I can seem to figure out how to do it in C++.
Here is an example in python of what I want to do in C++
#!/usr/bin/python
import random
array = [1,2,3,4,5]
random.shuffle(array)
print array
You can use
std::random_shufflefrom<algorithm>.Here’s a basic example from the page:
You can do it with anything that uses random access iterators, like
std::vectororstd::dequeor just a plain array like above.