C random string with letter limitation

This is a discussion on C random string with letter limitation within the C Programming forums, part of the General Programming Boards category; hello i have a small question that i need some help with, i would appreciate any help given How could ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    C random string with letter limitation

    hello i have a small question that i need some help with, i would appreciate any help given

    How could you create a string of 4 or 5 letters that have a limited number of uses.

    Example:
    a=2
    b=3
    c=4
    d=3
    e=2

    string = acbcbcbdecdeadc

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Start with aabbbccccdddee and shuffle.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    3
    How do you shuffle?
    and thnx for the fast reply

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Move one card from one spot in the deck to another. If you've got the dexterity for it, you can even shuffle more than one card at a time!


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    3
    i meant how do u shuffle in c programming, not in real life.
    could anyone help me, i googled it but what i found is not that good.
    plzz hlp me

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you know how to swap two variables? If not, that's what you need to learn to do. Once you know how to do that, you can apply that to your array.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,049
    Another way could be to generate a random number using the time "now" as the seed.
    Encode the characters say a=1 and e=5; then modulo the random number generated by 5.
    Whichever (encoded) character matches the remainder, is installed into the char array defined.

    Repeat all of the above steps until the char array is completely filled (excluding the null terminator).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. counting letter occurences in a string
    By pjr5043 in forum C++ Programming
    Replies: 35
    Last Post: 05-05-2008, 10:18 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 11:32 AM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 12:40 PM

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