Question regarding random numbers

This is a discussion on Question regarding random numbers within the C Programming forums, part of the General Programming Boards category; At first i am thankful to the people who have given answers to my questions. My questions are. 1. I ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    8

    Question regarding random numbers

    At first i am thankful to the people who have given answers to my questions.

    My questions are.

    1. I wld like to print a random letter in English alphabet. But here the condition is i should avoid A, E, I, O and U. Each time i run the program it should generate only consonant alphabet. How it is possible?

    2. How can we print a random character. Here the condition is it may print it from small case letters (a-z0 and from numerals (0-9). That means if we execute the program it should print a character either from small alphabets or from numerals.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    1. I wld like to print a random letter in English alphabet. But here the condition is i should avoid A, E, I, O and U. Each time i run the program it should generate only consonant alphabet. How it is possible?
    1. the right way - make an array of all consonants, and only choose from those.
    2. the lazy way - choose an alphabet randomly, and try again if you hit a vowel.

    choosing a letter can be done by, for example -
    Code:
    char c = 'a' + (rand() % 26);
    2. How can we print a random character. Here the condition is it may print it from small case letters (a-z0 and from numerals (0-9). That means if we execute the program it should print a character either from small alphabets or from numerals.
    Make a char array of candidates, and randomly choose from those.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Criteria based random numbers
    By alkisclio in forum C++ Programming
    Replies: 6
    Last Post: 09-14-2006, 12:29 PM
  2. calculating the variance of random numbers
    By Unregistered in forum C Programming
    Replies: 18
    Last Post: 11-22-2004, 07:16 AM
  3. Generating Random Numbers
    By FromHolland in forum C++ Programming
    Replies: 6
    Last Post: 06-16-2003, 09:05 AM
  4. 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
  5. Help generating random numbers in MFC
    By drb2k2 in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2003, 08:52 AM

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