to generate test data, you might think that it matters for deterministic data. In other words, every time you generate data, it is one and the same. Thus, it is easier to reproduce errors.
To do this, you can use hashbytes()over a determinate seed. In other words:
create function dbo.fn_RandishInt(@seed nvarchar(max), @min int, @max int)
returns int
as
begin
declare @crc bigint
declare @p float
set @crc = cast(cast(hashbytes('md5', @seed) as int) as bigint) & 0xffffffff
set @p = cast(@crc as float) / 4294967296
return round(((@max - @min) * @p) + @min, 0)
end
go
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS s,
char(dbo.fn_RandishInt(ROW_NUMBER() OVER (ORDER BY (SELECT 0)), 65, 66)) AS t
FROM
sys.objects
it will always give the same, random results.
source
share