Array problem

G

Guest

Can anybody tell me how I can put the elements of an array in a random
order? Like: 1,2,3,4,5 -> 3,2,5,1,4
 
T

Tim Love

Can anybody tell me how I can put the elements of an array in a random
order? Like: 1,2,3,4,5 -> 3,2,5,1,4
There's a std routine to shuffle vectors etc
random_shuffle(v.begin(), v.end());
 
J

John Harrison

Can anybody tell me how I can put the elements of an array in a random
order? Like: 1,2,3,4,5 -> 3,2,5,1,4

#include <algorithm>

int main()
{
int a[5] = {1, 2, 3, 4, 5};
std::random_shuffle(a, a + 5);
}

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,167
Messages
2,570,913
Members
47,454
Latest member
eibaloja

Latest Threads

Top