Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
-- 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())
SELECT RAND(2)
WAITFOR DELAY '00:00:02'
SELECT RAND(2)
USE Northwind
SELECT RAND(2)
USE myDB
declare @seed int; set @seed = 391247
declare @randnum int
declare @t table( randnum int )
DECLARE @cnt int; SET @cnt = 0
WHILE @cnt <=100
BEGIN
SET @cnt = @cnt + 1
SET @randnum = CONVERT(int, 1e6 * rand(@seed))
INSERT INTO @t SELECT @randnum
SET @seed = @randnum
END
select randnum from @t
SELECT RAND(RAND()*999983)
DECLARE @t table( randnum float )
DECLARE @cnt int; set @cnt = 0
WHILE @cnt <=10000
BEGIN
set @cnt = @cnt + 1
INSERT INTO @t
SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
+ (DATEPART(ss, GETDATE()) * 1000 )
+ DATEPART(ms, GETDATE()) )
END
SELECT randnum, count(*)
FROM @t
GROUP BY randnum
CREATE TABLE myTable
( id int identity(1, 1) primary key,
name varchar(20),
randnum int
)
INSERT INTO myTable(name) VALUES('Joe')
INSERT INTO myTable(name) VALUES('Bill')
INSERT INTO myTable(name) VALUES('Mary')
INSERT INTO myTable(name) VALUES('Fred')
INSERT INTO myTable(name) VALUES('Sue')
UPDATE myTable
SET randnum = 1 + 10*RAND()
SELECT * FROM myTable
SELECT name, NEWID()
FROM myTable
UPDATE myTable
SET randnum = 1 + 10*RAND(CHECKSUM(NEWID()))
UPDATE myTable
SET randnum = 1 + 10*RAND(CHECKSUM(*))
SELECT TOP 3 *
FROM myTable
ORDER BY NEWID()
SELECT IDENTITY(int, 1, 1) as randid, id
INTO #tmp
FROM
( SELECT TOP 100 PERCENT id
FROM myTable
ORDER BY NEWID()
) X
UPDATE myTable
SET randnum = #tmp.randid
FROM myTable
INNER JOIN #tmp ON myTable.id=#tmp.id
DROP TABLE #tmp
SELECT * FROM myTable
UPDATE myTable
SET randnum = NULL
INSERT INTO myTable (name, randnum)
SELECT name, randnum
FROM myTable
UPDATE T
SET randnum = Y.randnum
FROM myTable T
INNER JOIN
( SELECT TOP 100 PERCENT name, 1+10*RAND(CHECKSUM(NEWID())) AS randnum
FROM
( SELECT DISTINCT name
FROM myTable
) X
ORDER BY name
) Y ON T.name=Y.name
SELECT *
FROM myTable
ORDER BY name
SELECT DISTINCT name, CONVERT(int, NULL) as randnum
INTO #tmp
FROM myTable
UPDATE #tmp
SET randnum = 1+10*RAND(CHECKSUM(NEWID()))
UPDATE myTable
SET randnum = #tmp.randnum
FROM myTable
INNER JOIN #tmp on myTable.name=#tmp.name
DROP TABLE #tmp