In C-language, how can i pick a random character out of three characters. In those three characters there are both numbers and letters, for example 1Q2
In C-language, how can i pick a random character out of three characters. In those three characters there are both numbers and letters, for example 1Q2
A quick search of this forum for "how to pick a random number" brings me to How to pick a random number between x and y. Adapt post #6 to your needs.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Abuse C array indexing rules for fun an profit : char x = "1Q2"[rand() % 3];
Could easily be expanded to an arbitrary character array using a const char pointer and strlen() instead of hard-coding the array and length.