random string c++

#include <string>

string  gen_random(int len) {
    string s;
    static const char alphanum[] =
        "0123456789"
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz";

    for (int i = 0; i < len; ++i) {
        s += alphanum[rand() % (sizeof(alphanum) - 1)];
    }

    return s;
}

0
6
John Wheal 65 points

                                     
string  gen_random(int len) {
        string s;
        static const char alphanum[] =
            &quot;0123456789&quot;
            &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
            &quot;abcdefghijklmnopqrstuvwxyz&quot;;

        for (int i = 0; i &lt; len; ++i) {
            s+= alphanum[rand() % (sizeof(alphanum) - 1)];
             }

     return s;
    

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
random sttring generator c++ take random elements from string c++ c++ random generate string generate randomstring c++ get random string c++ random string bulder in c++ rand c++ string how to Randomize a string c++ set a random string in c++ c++ gen_random string how to generate a random string in c++ random string builder c++ cpp gen random string generating random letter strings c++ how to randomly generate strings in c++ c++ randomly generate string how to generate random strings in Cpp generating random string in cpp random string in cpp generate a random string in +c+ how to make random string in c++ generate random strings c++ c++ create random string creating a random string in c++ random string gen c++ string random c++ how to produce a random string in c++ &lt;random&gt; c++ string string random number c++ random strings in c++ c++ std random how to generate random charcters and append them to stringin c++ random number generator program in c++ stl c++ generate string c++ fixed random length string distribution generator string c++ how to generate random strings in c++ randomly generate string c++ how to take random string in c++ c++ string generator str random c++ generate a random string c++ c++ random char random string elements C++ generate random strings cpp how to create random strings c++ how can i generate random 3 characters in c++ within a,b,c random char generator c++ for a,b,c c++ generate random ascii strin increase sequencial alphabet strings in random C++ printing sequancial random alphabet in c++ create random text in c++ c++ random string generator c++ generate random string C++14 random string rand in string cpp c++ random number generator length how to genrate random string in c++ c++ make random string randomly generate an array of 1024 characters in c++ random string generator c how to make a string of random length in c++ how to creatae a name made up of random chars with random length between 8 and 16 in c++ random key generator c++ all unique characters random key generator c++ cpp get random string how to print random characters in c c generate randem string random string in c++ get int from string with random letters c random char in c random generator using string c++ ranom string in c++ random string c++ random string generator cpp generate 1000 random strings in c++ generate random character c++ generate a random string and its substring in c++ generate random string c++ random string generator c++ how to take a random string in cpp generate random strings in C++ cpp random string c++ random string how to generate random string c++ c program to change letter in string randomly c++ print random string int random string generator c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source