Professional Documents
Culture Documents
Recommended: Please try your approach on {IDE} first, before moving on to the
solution.
A ubiquitous use of unpredictable random characters is in cryptography, which
underlies most of the schemes which attempt to provide security in modern
communications (e.g. confidentiality, authentication, electronic commerce, etc).
Random numbers are also used in situations where “fairness” is approximated by
randomization, such as selecting jurors and military draft lotteries.
Random numbers have uses in physics such as electronic noise studies, engineering,
and operations research. Many methods of statistical analysis, such as the
bootstrap method, require random numbers.
Pseudo code :
First we initialize two character arrays, one containing all the alphabets and
other of given size n to store result.
Then we initialize the seed to current system time so that every time a new random
seed is generated.
Next, we use for loop till n and store random generated alphabets.
Below is C++ implementation of above approach:
return res;
}
// Driver code
int main()
{
srand(time(NULL));
int n = 10;
cout << printRandomString(n);
return 0;
}
Output
urdfwootzr
Time Complexity: O(n)
This program will print different characters every time we run the code