I am trying to generate random numbers in a range of 1 – 25 for 7 columns and the last column needs to have a range of 1 – 10
This is how I’m generating my random numbers.
SELECT ABS(CHECKSUM(NEWID()))%25 + 1 AS Number1
,ABS(CHECKSUM(NEWID()))%25 + 1 AS Number2
,ABS(CHECKSUM(NEWID()))%25 + 1 AS Number3
,ABS(CHECKSUM(NEWID()))%25 + 1 AS Number4
,ABS(CHECKSUM(NEWID()))%25 + 1 AS Number5
,ABS(CHECKSUM(NEWID()))%25 + 1 AS Number6
,ABS(CHECKSUM(NEWID()))%25 + 1 AS Number7
,ABS(CHECKSUM(NEWID()))%10 + 1 AS Number8 FROM GENERATE_SERIES(1, 1000000);
I was thinking to put the generation in a cursor so that after it generates 1 number set it will go through checks like
eg.
are any of the numbers repeating?
are any number sets the same?
and if it passes the check it will insert it into the table
also No. 8 can be a duplicate for columns 1 – 8 but columns 1 – 8 have the same number
The only issue I am having is how to incorporate the checks into the generation of the number sets, I assumed a cursor will be the best as it will run through the cursor each time for each number set that is generated and thus when it has generated all possible number sets it will just end.