Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Change the probability of the pseudo-random values

By Peter Petrov,

The usual practice, when we need some test data, is to employ the pseudo-random built-in function RAND(). We usually use it to produce a random value in some range and it produces these values with the same probabilities. Sometimes we need more "realistic" data when some values are more probable than others are. In this cases we can still use RAND() function. The simple "trick" is to call it to produce a random number into the desired range and then use this value as a one of the boundaries of a new range. Run the script to see the sequence that it will produce. Notice that you can apply the "trick" more times to produce values with more "different" probabilities.

Total article views: 245 | Views in the last 30 days: 1
 
Related Articles
FORUM

random records

select random records

FORUM

Random number generator

Random numbers

SCRIPT

random integer number scalar function

this produces a random integer between a certain range

ARTICLE

Random problems

Building random numbers can be challenging for people working in T-SQL. New author Chris Nowicki bri...

FORUM
Tags
data warehousing    
miscellaneous    
t-sql    
 
Contribute