Click here to monitor SSC
SQLServerCentral is supported by Redgate
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 @ 7:19 PM
Points: 42,047, Visits: 39,434
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."

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