Quick Question

Is there a function that randomly shuffles up an array?
Say I make a char array with the alphabet in it, and I want it to randomly print Letters from the char array. Thanks!
Ok thanks =P
I'm not understanding it.
D=
What do you don't understand? Post more specific question(s).
Last edited on
I can't understand how the code works, and what the syntax means.
I'm still learning things.
ok, this should get you started :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <algorithm>

int main() {

    char alphabet[26];
    for ( int i = 0; i < 26; ++i )
        alphabet[i] = i + 'a';

    std::random_shuffle(alphabet, alphabet+26);

    for ( int i = 0; i < 26; ++i )
        std::cout << alphabet[i] << ' ';

    return 0;
}


EDIT : edited a typo in code
Last edited on
You mean

 
std::random_shuffle( alphabet, alphabet + 26 );


Topic archived. No new replies allowed.