Create a VIEW using RAND function.
CREATE VIEW rndView
AS
SELECT RAND() rndResult
GO
Create a UDF using the same VIEW.
CREATE FUNCTION RandFn()
RETURNS DECIMAL(18,18)
AS
BEGIN
DECLARE @rndValue DECIMAL(18,18)
SELECT @rndValue = rndResult
FROM rndView
RETURN @rndValue
END
GO
Now execute the UDF and it will just work fine and return random result.
SELECT dbo.RandFn()
GO
类似的还有NEWID()