• Here's a "fix" for your code... doesn't change a thing in the code... just the way the "seed" for the RAND function works...

    select dbo.fx_getrandomnumber(500, 300, rand(CHECKSUM(NEWID())))

    FROM dbo.Tally

    WHERE N <= 10

    That will randomly generate 10 "different" integers with the understanding that it's the nature of random numbers to occasionally be duplicate in any set of random numbers.

    If I may suggest, if you need to write that much code to use a function, you may want to consider not even using a function. Just do it "inline".

    SELECT ABS(CHECKSUM(NEWID()))%(500-300+1)+300

    FROM dbo.Tally

    WHERE N <= 10

    --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)