Here's a quick proof of concept.
Set @Loops
to something big enough to make the statistics meaningful. 50k seems like a decent starting point.
Set @MinValue
to the lowest integer in your set and set @TotalValues
to how many integers you want in your set. 0 and 16 get you the 16 values [0-15]
, as noted in the question.
We're going to use a random function to cram 50k outputs into a temp table, then run some stats on it...
DECLARE @MinValue int
DECLARE @TotalValues int
SET @MinValue = 0
SET @TotalValues = 16
DECLARE @LoopCounter bigint
SET @LoopCounter = 0
DECLARE @Loops bigint
SET @Loops = 50000
CREATE TABLE #RandomValues
(
RandValue int
)
WHILE @LoopCounter < @Loops
BEGIN
INSERT INTO #RandomValues (RandValue) VALUES (FLOOR(RAND()*(@TotalValues-@MinValue)+@MinValue))
--you can plug into the right side of the above equation any other randomize formula you want to test
SET @LoopCounter = @LoopCounter + 1
END
--raw data query
SELECT
RandValue AS [Value],
COUNT(RandValue) AS [Occurrences],
((CONVERT(real, COUNT(RandValue))) / CONVERT(real, @Loops)) * 100.0 AS [Percentage]
FROM
#RandomValues
GROUP BY
RandValue
ORDER BY
RandValue ASC
--stats on your random query
SELECT
MIN([Percentage]) AS [Min %],
MAX([Percentage]) AS [Max %],
STDEV([Percentage]) AS [Standard Deviation]
FROM
(
SELECT
RandValue AS [Value],
COUNT(RandValue) AS [Occurrences],
((CONVERT(real, COUNT(RandValue))) / CONVERT(real, @Loops)) * 100.0 AS [Percentage]
FROM
#RandomValues
GROUP BY
RandValue
--ORDER BY
-- RandValue ASC
) DerivedRawData
DROP TABLE #RandomValues
Note that you can plug in any other randomizing formula into the right side of the INSERT
statement within the WHILE
loop then re-run to see if you like the results better. "Evenly distributed" is kinda subjective, but the standard deviation result is quantifiable and you can determine if it is acceptable or not.