Generating random characters

Since we've covered generating random strings from a set wordlist, let's look at generating random characters. The char data type is a single, one byte character.

A string is actually just a null-terminated sequence of characters, so the following lines of code produce the exact same result:

Stirng myStringLiteral = "hello";
string myString = { 'h', 'e', 'l', 'l', 'o', '\0' };

Likewise, the following code is semantically correct:

char myCharArray[6] = { 'h', 'e', 'l', 'l', 'o', '\0' };
string stringVersion = myCharArray;

Since a char is one byte, it has the possible integer representations of 0 to 255. Each of these decimal values represents a different character. A lookup table can found in the ASCII table. For example, ...

Get Procedural Content Generation for C++ Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.