The following command loads the relevant graphing procedures.

<<  Graphics`Graphics`

The following procedure generates a random letter, where the alphabet is of length
a, not counting the space. The space has probability q, and each letter has probability (1-q)/a.

randomletter[a_,  
        q_]  := 
Block[{r}, 
         r  =  Random[]; 
         If[
          r  >  1 - 
              q, 
              Return[
            0], 
              Return[
            Ceiling[a r/(1 - 
                      q)]]
            ]
]

Table[randomletter[5,  .3],  {i,  1000}];

Count[%14, 0]

The following procedure produces a list that is useful in the next procedure.  The input consists of a list of letter frequencies and q, the probability of a space.  The output list
is a list of subtotals of frequencies, with the property that if r is a random number  between 0 and 1, and r is between the (i-1)'st and i'th entry in this list of subtotals, then the output letter should be i (and when i is equal to the length of the subtotal list, a space is generated).  A 1 is added to the end of the output list.

createsubtotallist[letterfreq_,  
        q_]  := 
Block[{subtotallist  =  {}, 
            currenttotal  =  
            0, 
             i}, 
              For[i  =  1,  
          i  ≤  
            Length[letterfreq],  i++, 
                   subtotallist  =  
            Append[subtotallist,  
              currenttotal]; 
            currenttotal  =  
            currenttotal  +  
              letterfreq[[i]]
                     ]; 
               subtotallist  =  
          Append[subtotallist,  
            1]; 
               subtotallist  =  subtotallist*(1 - 
                q); 
               subtotallist  =  
          Append[subtotallist,  
            1]; 
         Return[
          subtotallist];
           ]

createsubtotallist[{ .1,   .2,   .7},   .1]

The following  procedure generates a random letter from an alphabet whose letters appear with frequencies given in the input list letterfreq.  We assume that a space occurs with probability q.  This procedure uses the output of the procedure createsubtotallist, to avoid lots of recalculation.  Thus, when this procedure is used, the procedure createsubtotallist must first be used.

randomunequalletter[
        subtotallist_]  := 
Block[{i, 
            r
           }, 
            r  =  
          Random[]; 
           i  =  
          1; 
           While[
          r  >  subtotallist[[i]], 
                       i++
                      ]; 
            Return[
          i - 1]
           ]

Table[randomunequalletter[%130], {j,  10}]

Length[%130]

Count[%132,  4]

The following procedure generates a list of n random words, where the alphabet is of length
a, not counting the space.  A string of letters, including a space, is generated, with the space having probability q, and each letter having probability (1-q)/a.

Clear[randomwordlist];
randomwordlist[a_,  q_,  
        n_]  := 
Block[{wordlist  =  {}, 
            currentletter, 
            currentword  =  {}, 
           i, 
           wordcount  =  
            0
          }, 
            While[
          wordcount  <  
            n, 
                      currentword  =  {}; 
                     currentletter  =  
            randomletter[a,  
              q]; 
                    While[currentletter  ≠  
              0, 
                                 currentword  =  
              Append[currentword,  
                currentletter]; 
                                  currentletter  =  
              randomletter[a, 
                q];
                                ]; 
                      If[
            Length[currentword]  >  
              0, 
                       wordlist  =  
              Append[wordlist,  
                currentword]; 
                       wordcount++
                   ];
                 ]; 
          Return[
          wordlist]
         ]

The following procedure creates a list of n words, using letters that are not necessarily equally probable.  This procedure uses the procedure randomunequalletter, which requires the list subtotallist.  This last list is created once by using the procedure createsubtotallist.  The number a is the length of the alphabet, not counting the space.

Clear[
        randomwordlistusingunequalletters];
randomwordlistusingunequalletters[a_,  subtotallist_,  
        n_]  := 
Block[{wordlist  =  {}, 
            currentletter, 
            currentword  =  {}, 
           i, 
           wordcount  =  
            0
          }, 
            While[
          wordcount  <  
            n, 
                      currentword  =  {}; 
                     currentletter  =  
            randomunequalletter[
              subtotallist]; 
                    While[
            currentletter  ≠  
              a + 1, 
                                 currentword  =  
              Append[currentword,  
                currentletter]; 
                                  currentletter  =  
              randomunequalletter[
                subtotallist];
                                ]; 
                      If[
            Length[currentword]  >  
              0, 
                       wordlist  =  
              Append[wordlist,  
                currentword]; 
                       wordcount++
                   ];
                 ]; 
          Return[
          wordlist]
         ]

randomwordlistusingunequalletters[3,  %130,  1000];

randomwordlist[5,  .3,  10000];

Sort[%]

Take[%51,  100]

For[i  =  1,  
      i  ≤  5,  i++, 
Print[i,  " ", 
        Count[%51,  {i}]]
]

The following procedure returns the i'th word of length k, using an alphabet of the numbers from 1 to a.  It must be the case that 1<= i <= a^k.

ithword[i_,  k_,  a_]  := 
      Return[IntegerDigits[i - 1,  a,  k] +  1]

Table[ithword[i,  2,  4],  {i,  1,  16}]

The following procedure returns the frequency counts of all of the k-digit words from an alphabet of length a in the list wordlist.

frequencycount[wordlist_,  a_,  
        k_]  := 
Block[{frequencies  =  {}, 
             i
           }, 
          For[i  =  1,  
          i  ≤  
            a^k,  i++, 
                  frequencies  =  
            Append[frequencies, 
              Count[wordlist,  
                ithword[i,  k ,  
                  a]] ]
                ]; 
          Return[
          frequencies]
          ]

frequencycount[%51,  5,  1]

frequencycount[%51,  5,  2]

frequencycount[%51,  5,  3]

(* The following procedure counts the frequencies of each entry in the sorted list wordlist.  The output is a sorted list of the frequencies, in decreasing order. *)

freqcount[
        wordlist_]  := 
Block[{outputlist  =  {}, 
            currentword, 
            currentplace =  
            1, 
           currentcount  =  
            1
}, 
            currentword  =  
          wordlist[[1]]; 
            currentplace  =  2; 
            While[
          currentplace  ≤  
            Length[wordlist], 
                         If[
              wordlist[[currentplace]]  ==  
                currentword, 
                               currentcount++; 
                               currentplace++, 
                                outputlist  =  
                Append[outputlist,  
                  currentcount]; 
                                currentword  =  
                wordlist[[currentplace]]; 
                               currentcount  =  
                1; 
                               currentplace++;
                             ];
                       ]; 
             outputlist  =  
          Append[outputlist,  
            currentcount]; 
             outputlist  =  
          Reverse[Sort[
              outputlist]]; 
            Return[
          outputlist]
           ]

freqcount[{1, 1, 2, 2, 2, 3, 4}]

freqcount[Sort[%15]]

freqcount[%25]

(* This procedure takes as input a list of frequencies, in decreasing order, and returns a list of ordered pairs, in which the first entry is a frequency (from the input list) and the second entry is its probability (i.e. the fraction of times that frequency appears in the input list). *)

freqprob[
        freqlist_]  := 
Block[{outputlist  =  {}, 
            currentfreq, 
            currentplace =  
            1, 
           currentcount  =  
            1, 
          numfreqs  =  
            Length[freqlist]
}, 
            currentfreq  =  
          freqlist[[1]]; 
            currentplace  =  2; 
            While[
          currentplace  ≤  
            Length[freqlist], 
                         If[
              freqlist[[currentplace]]  ==  
                currentfreq, 
                               currentcount++; 
                               currentplace++, 
                                outputlist  =  
                Append[outputlist,  {currentfreq, 
                    currentcount/
                      numfreqs}]; 
                                currentfreq  =  
                freqlist[[currentplace]]; 
                               currentcount  =  
                1; 
                               currentplace++;
                             ];
                       ]; 
             outputlist  =  
          Append[outputlist,  {currentfreq,  
              currentcount/
                numfreqs}]; 
             outputlist  =  
          Reverse[Sort[
              outputlist]]; 
            Return[
          outputlist]
           ]

The following procedure produces a log-log plot of frequency vs.rank,  The output from a call of the procedure randomwordlist[m,q,n] is assumed as the input in the procedure below.

freqvsrank[
        inputwordlist_]  := 
Block[{wordlist  =  
            inputwordlist, 
            freqlist  =  {}, 
             freqlist2  =  {}
           }, 
            freqlis  =  
          freqcount[
            Sort[wordlist]]; 
            freqlis2  =  
          Transpose[{Table[i,  {i,  Length[freqlis]}],  
              freqlis}]; 
            LogLogListPlot[freqlis2,  
          PlotRange  ->  
            All];
           ]

The following procedure produces a log-log plot of the probability of a frequency vs. frequency.  The output from a call of the procedure randomwordlist[m,q,n] is assumed as the input in the procedure below.

probfreqvsfreq[
        inputwordlist_]  := 
Block[{wordlist  =  
            inputwordlist, 
            freqlist  =  {}, 
            }, 
            freqlis  =  
          freqcount[
            Sort[wordlist]]; 
            freqcountlis  =  
          freqprob[
            freqlis]; 
            LogLogListPlot[freqcountlis,  
          PlotRange  ->  
            All];
           ]

The following procedure produces a log-log plot of frequency vs. rank, and another log-log plot of the probability of a frequency vs. frequency.  The inputs are m, the number of non-blank letters, q, the probability of a blank, and n, the number of words.  All non-blank letters are assumed to be equally probable.

twoplots[m_,  q_,  
        n_]  := 
Block[{wordlist  =  
            inputwordlist, 
              freqlis  =  {}, 
             freqcountlis  =  {}}, 
              wordlist  =  
          randomwordlist[m,  q,  
            n]; 
             freqlis  =  
          freqcount[
            Sort[wordlist]]; 
             freqlis2  =  
          Transpose[{Table[i,  {i,  Length[freqlis]}],  
              freqlis}]; 
            LogLogListPlot[freqlis2,  
          PlotRange  ->  
            All]; 
            freqcountlis  =  freqprob[
            freqlis]; 
            LogLogListPlot[freqcountlis,  
          PlotRange  ->  
            All];
             ]

twoplots[2,   .18,  1000]

randomwordlist[7,  1/8,  10000];

freqvsrank[%70]

probfreqvsfreq[%70]

LogLogPlot[2 10^3/x^1.069,  {x,  1,  10000}]

Show[%74,  %87]

N[Log[8]/Log[7]]

LogLogPlot[ .1/x^(1/1.0686),  {x,  1,  200}]

Show[%79,  %95]

LogLogPlot[ .1/x^2,  {x,  1,  200}]

Show[%79,  %97]