Here's my cut at it
| sequence ranges buckets |
sequence := Random seed: 5. "yes this is lame - pick a better seed"
ranges := #( 0.0 0.1 0.4 0.8 ).
buckets := Array new: (ranges size).
buckets atAllPut: 0.
500 timesRepeat: [ "or however many times you want"
\t| n index |
\tn := sequence next.
\tindex := ranges findLast: [:value | n >= value].
\tbuckets at: index put: ((buckets at: index) + 1)].
"This just prints out the results and could likely be done better with a stream"
ranges := ranges copyWith: 1.0. "stick a 1.0 on the end for completeness"
1 to: (ranges size-1) do: [:i |
\t| lo hi |
\tlo := ranges at: i.
\thi := ranges at: i+1.
\tTranscript show: ((lo asString), ' - ', (hi asString), ' : ', ((buckets at: i) asString)); cr]
There's also an iterator - pairsDo: which is handy for this sort of thing. The ranges array would have to look like
ranges := #(
0.0 0.1
0.1 0.4
0.4 0.8
0.8 1.0
).
But you'll still need to run your own counter to index into the buckets array.
ie:
index := 1.
ranges pairsDo: [:lo :hi |
(n isBetween: lo and: hi)
ifTrue: [buckets at: index put: (buckets at: index) + 1]
ifFalse: [index := index +1]]
The problem with this is you don't get a loop exit once you've found what you're looking for. So I use findLast which searches until found.