Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase «««123

Random number generator Expand / Collapse
Posted Monday, April 29, 2013 6:36 AM



Group: General Forum Members
Last Login: Today @ 10:30 PM
Points: 36,881, Visits: 33,717
Ah, apologies. I didn't understand what you were getting at. I see what you're saying now.

The singleton formula can be easily modified to take min/max parameters as follows using the classic domain range calculations for random numbers.

DECLARE @pMinRandom INT,
@pMaxRandom INT
UPDATE dbo.Client
SET RandomNumber = ABS(CHECKSUM(NEWID())) %(@pMaxRandom-@pMinRandom+1) +@pMiRandom

--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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1447481
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse