generate random letters

This is a discussion on generate random letters within the C++ Programming forums, part of the General Programming Boards category; how can i generate random letters? i was thinking of using ascii, but i dont know how to do that ...

  1. #1
    Unregistered
    Guest

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    rand() % 26 + 'A';

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    63
    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>
    srand(time(0));
    int num, let;
    num = rand() % 2 + 1;
    if (num == 1)
    let = rand() %26 + 'A';
    else
    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, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21