Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // randomChar
- //
- // Created by n0gul on 31/10/2014.
- // Copyright (c) 2014 n0gul. All rights reserved.
- //
- #include <iostream>
- #include <cstdlib>
- #include <string>
- int rand_a_b(int a, int b)
- {
- return rand()%((b+1)-a) +a;
- }
- int main(int argc, const char * argv[])
- {
- std::string str = "";
- unsigned int nombreDeCaractereAGenerer(0);
- char caractere = '\0';
- std::cout << "Combien de nombres ?" << std::endl;
- std::cin >> nombreDeCaractereAGenerer;
- srand(time(NULL)); // on initialise le générateur aléatoire
- for (unsigned char i = 0; i < nombreDeCaractereAGenerer; i++)
- {
- caractere = rand_a_b('A', 'Z'); // on prend un caractère ascii entre 65 (la touche "A") (inclus) et 90 (le Z) (inclus)
- str += caractere;
- std::cout << str << std::endl;
- }
- //std::cout << std::endl;
- //std::cout << "Hello, World!\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement