How to shuffle a string in C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>
#include <chrono>
#include <random>
#include <string>

int main() {
    std::string str = "C++ is a high-level, general-purpose programming language";
    
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    
    // Shuffle the string
    std::shuffle(str.begin(), str.end(), std::default_random_engine(seed));
    
    std::cout << str << std::endl;
}

  
  
/*
run:
  
eg+mesl+-hipigoggn r r,svuenuraglpeopCa-galml a  a heneir
  
*/

 



answered Nov 4, 2024 by avibootz

Related questions

2 answers 290 views
290 views asked Nov 1, 2021 by avibootz
2 answers 322 views
1 answer 269 views
269 views asked Feb 20, 2018 by avibootz
1 answer 258 views
258 views asked Feb 20, 2018 by avibootz
1 answer 254 views
254 views asked Feb 19, 2018 by avibootz
1 answer 278 views
278 views asked Feb 19, 2018 by avibootz
1 answer 160 views
160 views asked Nov 3, 2024 by avibootz
...