Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. what is the maximum combination for generate random string of given length?

what is the maximum combination for generate random string of given length?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structureshelplounge
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    Hi all, char possibles[37] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; i am renerating random string with help of rand function. how can i calculate the maximum combination for generate random string of given length? like if i give length = 4? so how cany maximum string generated of length 4 from given cahr array? please help me for this. thanks in advance.

    R T enhzflepE 3 Replies Last reply
    0
    • L Le rner

      Hi all, char possibles[37] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; i am renerating random string with help of rand function. how can i calculate the maximum combination for generate random string of given length? like if i give length = 4? so how cany maximum string generated of length 4 from given cahr array? please help me for this. thanks in advance.

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      It's known as Permutation[^], and there's formulae on that page that answers your question. By the way, this is not even a programming question, and has nothing to do with C++ or MFC.

      "Real men drive manual transmission" - Rajesh.

      1 Reply Last reply
      0
      • L Le rner

        Hi all, char possibles[37] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; i am renerating random string with help of rand function. how can i calculate the maximum combination for generate random string of given length? like if i give length = 4? so how cany maximum string generated of length 4 from given cahr array? please help me for this. thanks in advance.

        T Offline
        T Offline
        T RATHA KRISHNAN
        wrote on last edited by
        #3

        If order is important you have to use "Permutation". Otherwise you have to use "Combination". You have to select 4 characters out of the 36 characters. 36c4 is what you need. 36!/32!*4! is the way to calculate if my memory is good.

        1 Reply Last reply
        0
        • L Le rner

          Hi all, char possibles[37] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; i am renerating random string with help of rand function. how can i calculate the maximum combination for generate random string of given length? like if i give length = 4? so how cany maximum string generated of length 4 from given cahr array? please help me for this. thanks in advance.

          enhzflepE Offline
          enhzflepE Offline
          enhzflep
          wrote on last edited by
          #4

          Depends on whether or not a character may be repeated in a string. If so, it's very,very,very easy: # combinations = pow(numCharsToChooseFrom, lengthOfGeneratedString) 4 char string - 37^4 = 1,874,161 5 char string - 37^5 = 69,343,957 If a character may not be repeated, it is a little more involved. # combinations = (numCharsToChooseFrom!) / ((numCharsToChooseFrom-lengthOfGeneratedString)!) 4 character string - 37 * 36 * 35 * 34 = 1,585,080 5 char string - 37 * 36 * 35 * 34 * 33 = 52,307,640 or to put it more simply 4 character string - (37! / 33!) = 1,585,080 5 char string - (37! / 32!) = 52,307,640 Where the ! operator means factorial[^].

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups