March 2, 2023 at 10:29 pm
LOL.. He also wants "random" and "unique"... Given that any randomly generated number always has the potential to collide with another randomly generated number, the base requirements are a contradiction right out of the gate.
Considering that contradiction the best we can do is give the appearance of "random" and "unique" to the casual observer. Varying the length is "doable" but would only create headaches down the road.
BUT... Just because we shouldn't, doesn't mean we can't! XD
WITH
cte_n1 (n) AS (SELECT 1 FROM (VALUES (1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) n (n)),-- 10
cte_n2 (n) AS (SELECT 1 FROM cte_n1 a CROSS JOIN cte_n1 b),-- 100
cte_n3 (n) AS (SELECT 1 FROM cte_n2 a CROSS JOIN cte_n2 b),-- 10,000
cte_Tally (n) AS (
SELECT TOP(10000000)-- (10M rows to be generated)
ROW_NUMBER() OVER (ORDER BY a.n)
FROM
cte_n3 a CROSS JOIN cte_n3 b-- 100,000,000
ORDER BY
a.n
)
SELECT
n = ROW_NUMBER() OVER (ORDER BY NEWID() ),
rand_num = t.n + lv.len_val
FROM
cte_Tally t
CROSS APPLY ( VALUES (11 * CONVERT(bigint, POWER(10.0, ABS(CHECKSUM(NEWID())) % 5 + 8))) ) lv (len_val)
GO
March 2, 2023 at 10:33 pm
I just wanna know what he actually wants. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 16 through 17 (of 17 total)
You must be logged in to reply to this topic. Login to reply