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

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
H
Help Net Security
小众软件
小众软件
N
Netflix TechBlog - Medium
C
Check Point Blog
量子位
Last Week in AI
Last Week in AI
GbyAI
GbyAI
Martin Fowler
Martin Fowler
M
MIT News - Artificial intelligence
博客园 - 聂微东
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
D
DataBreaches.Net
Project Zero
Project Zero
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
Security Latest
Security Latest
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
I
Intezer
L
Lohrmann on Cybersecurity
Cyberwarzone
Cyberwarzone
博客园_首页
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
P
Palo Alto Networks Blog
V
V2EX
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
The Exploit Database - CXSecurity.com
The Hacker News
The Hacker News
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
The Register - Security
The Register - Security
L
LINUX DO - 热门话题
P
Privacy & Cybersecurity Law Blog
Scott Helme
Scott Helme
F
Full Disclosure
博客园 - 司徒正美
Recent Announcements
Recent Announcements
IT之家
IT之家
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Attack and Defense Labs
Attack and Defense Labs
Cloudbric
Cloudbric
Help Net Security
Help Net Security
The Last Watchdog
The Last Watchdog

博客园 - 举重-若轻

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/