@markr,
The idea behind the approach I landed upon was to improve the likelihood of longer clips by giving them more chances to be selected - using jagged arrays - in the arrays I placed "lots" that represented the length of the clip to be played - in the selection array that represents 30 seconds remaining in the segment 300 lots are created for a 30 second clip to be chosen tapering down to 10 lots for a 1 second clip.
In VB I wrote a function to create weights for each clip length:
Code: Private Sub SetClipWeights(WeightedClipLengths()() As Integer)
Dim w, x, y, z As Integer
For w = WeightedClipLengths.Count - 1 To 0 Step -1
y = 0
For x = w To 0 Step -1
For z = CInt((WeightedClipLengths.Count * 10) / (WeightedClipLengths.Count - x)) To 1 Step -1
ReDim Preserve WeightedClipLengths(w)(y)
WeightedClipLengths(w)(y) = x + 1
y += 1
Next
Next
Next
End Sub
I wrote the following generalized function to show the number of times a particular clip length was randomly selected:
Code: Private Sub TestClipWeights(WeightedClipLengths()() As Integer)
Dim SegmentLength = WeightedClipLengths.Count
Dim ClipFrequency(SegmentLength - 1) As Integer
Dim RemainingSegmentLength As Integer = SegmentLength
For x = 0 To 999999
Dim ClipLength As Integer = WeightedClipLengths(RemainingSegmentLength - 1)(Math.Floor(Rnd() * WeightedClipLengths(RemainingSegmentLength - 1).Count))
ClipFrequency(ClipLength - 1) += 1
RemainingSegmentLength -= ClipLength
If RemainingSegmentLength = 0 Then
RemainingSegmentLength = SegmentLength
End If
Next
End Sub
Called by the follow snippet:
Code:
Private WeightedClipLengthsSegment As Integer()() = New Integer(30)() {}
...
SetClipWeights(WeightedClipLengthsSegment)
TestClipWeights(WeightedClipLengthsSegmentA)
The frequencies of the longest clips were significantly boosted:
Secs Hit Frequency
(1) 268390
(2) 107179
(3) 65726
(4) 42842
(5) 33157
(6) 25085
(7) 19389
(8) 17001
(9) 15711
(10) 13101
(11) 12198
(12) 11474
(13) 11053
(14) 10705
(15) 10438
(16) 10033
(17) 9744
(18) 10282
(19) 10395
(20) 10766
(21) 11477
(22) 12282
(23) 13574
(24) 14890
(25) 17049
(26) 19825
(27) 24186
(28) 31733
(29) 46625
(30) 93690
As compared to a simple random partitioning where a random amount of the remaining segment is chosen:
Secs Hit Frequency
(1) 250855
(2) 125268
(3) 83563
(4) 62320
(5) 49822
(6) 41695
(7) 35686
(8) 31159
(9) 27695
(10) 24780
(11) 22866
(12) 20805
(13) 19459
(14) 17991
(15) 16757
(16) 15738
(17) 14634
(18) 13964
(19) 13197
(20) 12562
(21) 11898
(22) 11460
(23) 10907
(24) 10406
(25) 9999
(26) 9548
(27) 9310
(28) 8765
(29) 8618
(30) 8273
To my ear it's a much more pleasant distribution....