• stan.teitelbaum (2/15/2010)


    Thanks Jeff.

    That's my point. If something can generate both a negative and positive number 2, they may look random but abs reverses that effect.

    Also, it seems to us that RAND is doing fine between rows since the seed being passed as proposed is changing.

    I've actually used both. If you think about it, using RAND(Checksum(NewID())) will only generate as many unique values as Checksum(NewID()) in any given run since Checksum(NewID()) is what generates the "unique seed".

    So it comes down to what kind of numbers do you need? Is it better to work from a float and muliply it out, or start with a big number and make it smaller to fit your actual allowable range. Since they're both basically the same, I tned to work with what is fastest to generate (i.e. Jeff's method listed above).

    By the way - RAND() isn't random at all. For example, try running this:

    select rand(1)

    go

    select rand(1)

    go

    select rand(1)

    go

    select rand(1)

    go

    select rand(1)

    go

    select rand(1)

    In other words - it generates a predictable result for the same seed, even on separate runs and on different sessions. The only thing that makes it "seem" random is that it will "pick" a seed during different runs if you don't pass it a seed.

    It also apparently has something that only uses positive seeds , since

    RAND(1) = RAND(-1)

    So again, you really don't get anything other that somewhat slower perf out of using RAND().

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?