I've found a lot of answers where the call to RAND
is constantly being reseeded, but this means that while different values are created for each row, the operation cannot be repeated with the same result. Is there any way to ensure that each row gets a new value but where it is still seeded by the initial call?
The below attempts don't work:
UPDATE #TestTable
SET
Number = CONVERT(INT, FLOOR(RAND(CHECKSUM(NEWID())) * 1000))
Every row has a different value, but every time I run it the values for a given row are changed.
DECLARE @RandomSeeder FLOAT;
--Seeds the value, probably a better way to do this.
SELECT @RandomSeeder = RAND(5336);
UPDATE #TestTable
SET
Number = CONVERT(INT, FLOOR(RAND() * 1000));
It appears like RAND is called once and then that value is used in every row.