Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to generate random lowercase letters in C++

3 Answers

0 votes
#include <iostream>
#include <ctime>

using namespace std;

char GetRandomLowercaseLetter(void);

int main()
{
	srand((unsigned)time(NULL));

	for (int i = 0; i < 10; i++)
		cout << GetRandomLowercaseLetter() << " ";

	return 0;
}
char GetRandomLowercaseLetter(void)
{
	int n = rand() % 26; // 0 - 25
	char ch = (char)('a' + n);

	return ch;
}


/*
run:

p x w w m z v a c v

*/

 



answered Feb 15, 2017 by avibootz
0 votes
#include <iostream>
#include <ctime> 

using namespace std;

char GetRandomLowercaseLetter(void);

int main()
{
	srand((unsigned)time(NULL));

	for (int i = 0; i < 10; i++)
		cout << GetRandomLowercaseLetter() << " ";

	return 0;
}
char GetRandomLowercaseLetter(void)
{
	return 'a' + (rand() % 26);
}

/*
run:

l d g g n d o n t p

*/

 



answered Feb 16, 2017 by avibootz
0 votes
#include <iostream>
#include <ctime> 

using namespace std;

char GetRandomLowercaseLetter(void);

int main()
{
	srand((unsigned)time(NULL));

	for (int i = 0; i < 10; i++)
		cout << GetRandomLowercaseLetter() << " ";

	return 0;
}
char GetRandomLowercaseLetter(void)
{
	return "abcdefghijklmnopqrstuvwxyz"[rand() % 26];
}

/*
run:

p d m n s p m o i o

*/

 



answered Feb 16, 2017 by avibootz

Related questions

4 answers 267 views
267 views asked Feb 15, 2017 by avibootz
1 answer 92 views
1 answer 83 views
1 answer 78 views
1 answer 79 views
3 answers 130 views
2 answers 101 views
...