Generating the Nth combination of a binomial coefficient I'm designing a protocol, and need a bit of help. I am able to neatly condense the problem I am having into a allegory, I hope it doesn't sound too contrived.

Alice has flipped a coin t times, and has told me it has landed on heads k times.
From this, I am able to figure out how many different possible combinations of ways that Alice could have got this result:

function binom(t, k) {
    var coeff = 1;
    for (var i = t-k+1; i <= t; i++) coeff *= i;
    for (var i = 1;     i <= k; i++) coeff /= i;
    return coeff;
}

but now Alice wants to tell me the precise combination of heads-and-tails to she got, however she is restricted to only telling me a single number, the Nth possible way of generating the results she flipped. 
So describe an algorithm that turns t (total coin flips), k (amount of heads) and n into a sequence of heads-and-tails.
There are multiple ways of ordering all possible combinations, so there are multiple answer. But in my case, it doesn't matter how Alice orders the combinations (and thus the N she gives me) as long as I have a procedure to efficiently decode it.
 A: I've tested the following and it seems to work. It's in SQL as opposed to C but I hope you can follow the syntax. I'm not sure how much explanation you need but let me know if you have questions. The dbo.Choose() function is the same as your binom() function.
    -- Parameters
declare @t int; set @t = 8
declare @k int; set @k = 3
declare @n int; set @n = 7
    -- Variables
declare @seq varchar(8000); set @seq = ''
declare @m int; set @m = @n
declare @NumberOfCombinations int; set @NumberOfCombinations = dbo.Choose(@t, @k)
declare @HeadsRemaining int; set @HeadsRemaining = @k
declare @FlipsRemaining int; set @FlipsRemaining = @t
    -- .
    -- Work left-to-right: in each iteration, decide if the char is H or T, then
    -- set up the variables for the next iteration.
while @FlipsRemaining > 0 begin
    if @m <= @NumberOfCombinations * @HeadsRemaining / @FlipsRemaining begin
        -- Since C(t-1,k-1) / C(t,k) = k/t is the proportion of entries starting with H
        -- and same rule then applies at each subsequent level.
        set @seq = @seq + 'H'
        set @NumberOfCombinations = @NumberOfCombinations * @HeadsRemaining / @FlipsRemaining
        set @HeadsRemaining = @HeadsRemaining - 1
    end
    else begin
        set @seq = @seq + 'T'
        set @m = @m - @NumberOfCombinations * @HeadsRemaining / @FlipsRemaining
        set @NumberOfCombinations = @NumberOfCombinations * (@FlipsRemaining - @HeadsRemaining) / @FlipsRemaining
    end
    set @FlipsRemaining = @FlipsRemaining - 1
end
select @seq

This works on the following style of ordering, starting the H's leftmost and ending with H's rightmost. ($t=5, k=3$):
\begin{eqnarray*}
1 && HHHTT \\
2 && HHTHT \\
3 && HHTTH \\
4 && HTHHT \\
5 && HTHTH \\
6 && HTTHH \\
7 && THHHT \\
8 && THHTH \\
9 && THTHH \\
10 && TTHHH.
\end{eqnarray*}
So, $t=5,k=3,n=5$ results in HTHTH.
