- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to generate random alphabets
In this tutorial, we will be discussing a program to generate random alphabets.
For this, we will have a fixed size of array/string and use the rand() function to generate a random string of alphabets.
Example
#include <bits/stdc++.h> using namespace std; const int MAX = 26; //generating a string of random alphabets string gen_random(int n){ char alphabet[MAX] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; string res = ""; for (int i = 0; i < n; i++) res = res + alphabet[rand() % MAX]; return res; } int main(){ srand(time(NULL)); int n = 7; cout << gen_random(n) << endl; return 0; }
Output
gwqrgpa
- Related Articles
- C++ program to generate random number
- C++ Program to Generate Random Hexadecimal Bytes
- C# Program to generate random lowercase letter
- C# program to generate secure random numbers
- Write a program in Python to generate five random even index lowercase alphabets in a series
- Java program to generate random numbers
- C++ Program to Generate a Random Subset by Coin Flipping
- C++ Program to Generate Random Numbers Using Middle Square Method
- C++ Program to Generate Random Numbers Using Probability Distribution Function
- Java Program to generate random numbers string
- C++ Program to Generate Random Numbers Using Multiply with Carry Method
- Java Program to generate random number with restrictions
- Java Program to generate n distinct random numbers
- Generate random numbers using C++11 random library
- Java Program to generate random numbers with no duplicates

Advertisements