• Holy Moly! The distribution of "R" and "T" suck with my method! I don't quite understand it because the distribution of "C" is nearly flat as you would expect with random numbers. Here's the test code if you'd like to play...

    WITH

    cteC AS

    ( --=== Determine "C"

    SELECT CountC = ABS(CHECKSUM(NEWID()))%16+3

    FROM dbo.Tally t

    WHERE t.N <= 10000

    ),

    cteR AS

    ( --=== Determine "R" constrained by "C"

    SELECT CountC,

    CountR = ABS(CHECKSUM(NEWID()))%(25-CountC-6)+3

    FROM cteC

    ),

    cteT AS

    ( --=== Determine "T" constrained by "C" and "R"

    SELECT CountC,

    CountR,

    CountT = 25-CountC-CountR

    FROM cteR

    ) --=== Unpivot the 3 columns of data and do counts of occurances for each Count"x" value.

    SELECT unpvt.CountName, unpvt.CountX, COUNT(*) AS Occurances

    FROM (

    SELECT CountC,CountR,CountT

    FROM cteT

    ) pvt

    UNPIVOT (

    CountX FOR CountName IN (CountC,CountR,CountT)

    )AS unpvt

    GROUP BY unpvt.CountName, unpvt.CountX

    ORDER BY unpvt.CountName, unpvt.CountX

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)