Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
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

random records

select random records


Random number generator

Random numbers


random integer number scalar function

this produces a random integer between a certain range


Random problems

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

data warehousing    

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones