Does anyone know of a way to generate a RNGCryptoServiceProvider-like random number in T-SQL without having to register any .NET Assemblies?
Does anyone know of a way to generate a RNGCryptoServiceProvider-like random number in T-SQL
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
SELECT CHECKSUM(NEWID())gives you a 32 signed integer based on GUIDs. You can use this as base: it’s pretty much the best SQL wayYou can use it to seed RAND (because RAND is the same for all rows in a single select.
A signed 64 bit integer:
With some playing around you could cast and/or concatenate to get binary(“multiples of 4”) etc to build up a byte array… I’ve not used the RAND thingy though to emulate directly