• If it needs to be unique, why does it need to be random?

    Would a sequential (identity) number accomplish what you need?

    If it truly needs to be both random and unique, you may want to pre-generate the numbers, then use an identity field to link to them:

    create table RandomNumbers (

    ID int primary key,

    Number int)

    go

    ;with

    CTE1 (Number) as

    (select abs(checksum(newid()))/100

    from common.dbo.bignumbers bn1,

    common.dbo.bignumbers bn2),

    CTE2 (Number) as

    (select distinct number

    from cte1)

    insert into dbo.randomnumbers (id, number)

    select row_number() over (order by newid()), number

    from cte2

    Then, put an identity column in your table where you need a random number, and join it to the RandomNumbers table to get your random number.

    On my desktop computer, this took about 10 seconds to generate about 1-million unique, random numbers.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon