You could use a 3-column table, storing
id
random-value
hash(concat(id, random-value))
You could also generate new random values for every new set of data retrieved too.
If you are dealing with simultaneous sets of data being distributed at once, you could add a fourth column which would keep a "data-set identifier". This value would then be the same for all ids retrieved in a single query, such as the time the data is retrieved or a random number. Or perhaps you already have a user session and could use that to id each data set?
hash could be created using any built in hashing function. If you are using SQL server, you could use HASH_BYTES, which allows for md5 and sha512 among others. The random value would then be generated by
ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT)) AS [RandomNumber]
Using rand() produces the same value for all rows in a select (SQL Server), whereas newid() creates a unique value for every row. Do note that newid() returns data of uniqueidentifier type and must be cast accordingly. However, I do not know if subsequent calls to newid() for the same row will keep returning the same result. That is, I do not know if you can re-use NEWID() twice on each row
INSERT INTO gate_table SELECT (
id
, ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT))
, HASH_BYTES('md5', CONCAT(id, ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT))
[, optionally the "data-set-identifier"]
);
or if you'd have to store the result of the first call for subsequent use. And I don't know if selecting into a variable for later reference in the same row would work or not. I.e. this
SELECT id, @the_rand = rand-generating-expression(), hash(concat(id, @the_rand))