惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Threat Research - Cisco Blogs
P
Privacy & Cybersecurity Law Blog
The Hacker News
The Hacker News
H
Heimdal Security Blog
W
WeLiveSecurity
L
LINUX DO - 热门话题
Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
The Last Watchdog
The Last Watchdog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
D
DataBreaches.Net
I
Intezer
Webroot Blog
Webroot Blog
C
Cisco Blogs
AWS News Blog
AWS News Blog
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
罗磊的独立博客
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Schneier on Security
Schneier on Security
宝玉的分享
宝玉的分享
博客园 - 叶小钗
PCI Perspectives
PCI Perspectives
D
Docker
Scott Helme
Scott Helme
NISL@THU
NISL@THU
J
Java Code Geeks
B
Blog RSS Feed
Google Online Security Blog
Google Online Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Exploit Database - CXSecurity.com
AI
AI
美团技术团队
Cloudbric
Cloudbric
月光博客
月光博客
P
Proofpoint News Feed
T
Tailwind CSS Blog
Google DeepMind News
Google DeepMind News
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Cloudflare Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

博客园 - 举重-若轻

Survey 2遍的解决办法 Error occurred in deployment step 'Activate Features': Feature with Id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' is not installed in this farm using powershell to change the some sub-webs' system master page AssetUrlSelector export to excel 用powershell更新user profile service中的一个字段 create a 全局临时表 Remote Debugging GAC'd Assemblies in SharePoint get all user profiles redirecting to custom user profile page css的em概念 异步调用的一个例子 .NET种Json时对单引号和特殊字符串的处理 CSS备忘 SharePoint 资料 Server.MapPath方法的应用方法 JSON的客户端和服务器操作 jquery 参考材料 备忘 用powershell更新user的display name
Generate a random integrater
举重-若轻 · 2012-12-12 · via 博客园 - 举重-若轻

SQL SERVER – Random Number Generator Script – SQL Query

April 29, 2007 by pinaldave

Random Number Generator

There are many methods to generate random number in SQL Server.

Method 1 : Generate Random Numbers (Int) between Rang
---- Create the variables for the random number generation
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT

---- This will create a random number between 1 and 999
SET @Lower ---- The lowest random number
SET @Upper 999 ---- The highest random number
SELECT @Random ROUND(((@Upper @Lower -1) * RAND() + @Lower), 0)
SELECT @Random

Method 2 : Generate Random Float Numbers
SELECT RAND( (DATEPART(mmGETDATE()) * 100000 )
+ (
DATEPART(ssGETDATE()) * 1000 )
DATEPART(msGETDATE()) )


Method 3 : Random Numbers Quick Scripts

---- random float from 0 up to 20 - [0, 20)
SELECT 20*RAND()
-- random float from 10 up to 30 - [10, 30)
SELECT 10 + (30-10)*RAND()
--random integer BETWEEN 0
AND 20 [0, 20]
SELECT CONVERT(INT, (20+1)*RAND())
----random integer BETWEEN 10
AND 30 [10, 30]
SELECT 10 CONVERT(INT, (30-10+1)*RAND())


Method 4 : Random Numbers (Float, Int) Tables Based with Time

DECLARE @t TABLErandnum float )
DECLARE @cnt INTSET @cnt 0
WHILE @cnt <=10000
BEGIN
SET 
@cnt @cnt 1
INSERT INTO @t
SELECT RAND( (DATEPART(mmGETDATE()) * 100000 )
+ (
DATEPART(ssGETDATE()) * 1000 )
DATEPART(msGETDATE()) )
END
SELECT 
randnumCOUNT(*)
FROM @t
GROUP BY randnum


Method 5 : Random number on a per row basis

---- The distribution is pretty good however there are the occasional peaks.
---- If you want to change the range of values just change the 1000 to the maximum value you want.
---- Use this as the source of a report server report and chart the results to see the distribution
SELECT randomNumberCOUNT(1countOfRandomNumber
FROM (
SELECT ABS(CAST(NEWID() AS binary(6)) %1000) + 1 randomNumber
FROM sysobjectssample
GROUP BY randomNumber
ORDER BY randomNumber

http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/