2 replies

Last post Nov 26, 2016 07:07 AM by Cathy Zou

• sudip_inn

Contributor

2231 Points

3706 Posts

How to show random number

i use below script to show random number. so any other way exist to achieve the same. thanks

```DECLARE @UpperValue INT
DECLARE @LowerValue INT

SET @UpperValue = 10
SET @LowerValue = 1

SELECT ROUND(((@UpperValue - @LowerValue -1) * RAND() + @LowerValue), 0)```

• ketan_al

Contributor

4790 Points

1211 Posts

Re: How to show random number

Ketan Lohar
http://www.ketscode.com

MCP, MCTS,MCPD (Microsoft Azure Developer)

• Cathy Zou

Star

8660 Points

2882 Posts

Re: How to show random number

Nov 26, 2016 07:07 AM|Cathy Zou|LINK

Hi sudip_inn,

As far as I know and through referring to lot of article about how to Generate Random Numbers (Int) between Rang.

It seems that all ways are similar.

Following is same similar way. You could refer to it.

```DECLARE @UpperValue INT
DECLARE @LowerValue INT

SET @UpperValue = 10
SET @LowerValue = 1
SELECT ROUND(((@UpperValue - @LowerValue -1) * RAND() + @LowerValue), 0)
--SELECT CONVERT(INT,@UpperValue*RAND() +@LowerValue)  using convert to cast result to int

--SELECT FLOOR(RAND()*(@UpperValue-@LowerValue)+@LowerValue)  using FLOOR to cast result to int

--SELECT CONVERT(INT, @LowerValue+(@UpperValue-@LowerValue)*RAND())  ```