Thread: generate random letters

  1. #1

    generate random letters

    how can i generate random letters?
    i was thinking of using ascii, but i dont know how to do that either...

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    rand() % 26 + 'A';

  3. #3
    Registered User
    Join Date
    May 2002
    Well I am assuming that you want to have lower and upper case letters.

    So here is my solution, don't know how well it will work:
    #include <time.h>
    #include <stdlib.h>
    int num, let;
    num = rand() % 2 + 1;
    if (num == 1)
    let = rand() %26 + 'A';
    let = rand() %26 + 'a';
    cout << let << endl;

    That should work, I am not sure how efficient it is though.

    Just try it.
    tudehopet uses Borland Compiler 5.5
    and Visual C++ 6.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating random letters
    By ominub in forum C Programming
    Replies: 6
    Last Post: 04-29-2009, 01:12 AM
  2. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  3. Generate random numbers in Lucky7 project using C#
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 04-11-2003, 11:03 PM
  4. Ask about generate Random number
    By ooosawaddee3 in forum C Programming
    Replies: 2
    Last Post: 07-01-2002, 04:30 AM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM