1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$ irb
>> a = "a"
=> "a"
>> b = "b"
=> "b"
>> c = "c"
=> "c"
>> xs = [a,b,c,c,a,b,b,a,c,a,b]
=> ["a", "b", "c", "c", "a", "b", "b", "a", "c", "a", "b"]
>> def myrand
>>     r = rand; puts r; r
>> end
=> nil
>> xs.sort { myrand }
0.251169604033106
0.358249280861213
0.659588709549105
0.334159476300187
0.625159710522954
0.357627556986228
0.514087924904997
0.0428274630027364
0.770310028996097
0.253427157691787
0.0842565890951809
0.820006085529666
0.18484474647833
0.00826439206381324
0.35343769501479
0.0299901312200795
0.698834926441882
0.669533356288473
0.833968050310589
0.470969867559324
0.174675392572108
0.0129921016826907
0.903346816078078
0.600756504491988
0.559357544203663
0.958337959581317
0.36905840165631
0.871050816929698
0.405577639124173
0.11685891145893
=> ["b", "b", "a", "b", "c", "a", "a", "c", "c", "a", "b"]
>>