I've got a statement that inserts values into a table based on a random value and another value
INSERT INTO TRAINER_SYNC (Steps, TrainerId, SyncDate)
SELECT AverageSteps * (RAND()*(1.15-0.85)+0.85), Id, GETDATE()
FROM TRAINER
This works fine, but whenever two "Trainers" have the same "AverageSteps", the number inserted into the table is always the same.
For example, if all the trainers have average steps of 10000
, here is the result in the TRAINER_SYNC
table
Id TrainerId SyncDate Steps
10 1 2018-10-20 18:42:16.407 9482
11 2 2018-10-20 18:42:16.407 9482
12 3 2018-10-20 18:42:16.407 9482
13 4 2018-10-20 18:42:16.407 9482
14 5 2018-10-20 18:42:16.407 9482
15 6 2018-10-20 18:42:16.407 9482
16 7 2018-10-20 18:42:16.407 9482
17 8 2018-10-20 18:42:16.407 9482
18 9 2018-10-20 18:42:16.407 9482
Is there a way to get the RAND()
in the insert statement to be more... "random"? I'm not sure what it is called, but reset the initial seed so each iteration of the insert gives me a different random value?