Generating random 6 digit numbers

  • I found that generating random numbers is a task best done in code. Generating random numbers in SQL betrays a pattern, which makes repetitive executions predictable.

  • Jeff Moden (12/29/2008)


    The cast to VarBinary takes more time, Michael. That's the way I used to do it before Peter Larson and Matt Miller showed me this other way.

    I actually had more concerns about how random the distribution of numbers would be in this case, since the largest possible integer is only 2,147 times 999,999, while the largest 7 byte BIGINT is 4,503,604,130 times larger than 999,999.

    I donโ€™t think it would be easy to test the randomness of the distribution without running massive Monte Carlo simulations to see if there was any pattern.

  • Yeah... you're right on both counts... not enough coffee here... ๐Ÿ˜‰

    --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)
    Intro to Tally Tables and Functions

Viewing 3 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply