Recently, I systematically read erlang. Now I use erlang programming as the learning material. After reading the first seven or eight chapters, I tried to write something and found that I was helpless, there are very few materials and documents that can help. In fact, I hope someone can study or discuss it together. Today's question: a List in disorder. Method 1: a more sophisticated disordered solution. [Php]-module (shuffle ). -export ([do/1]). do (L)-> Len = length (L), NL = lists: map (fun (X)-> {random: uniform (Len), X} end, L ), NLL = lists: sort (NL), [V | |{_, V} <-NLL]. in fact, this problem is quite confusing to me. Once a variable is assigned a value, it cannot be modified. This feature makes the idea and idea of writing a program completely different. My above practice is to use a random number to generate a list like [{Rand1, Elem1},..., {RandN, ElemN. Then, sort it by sort and print the Elem again. The unordered result is achieved. The result is roughly as follows: [php] 45> c (shuffle ). {OK, shuffle} 46> shuffle: do ([1, 2, 3, 4, 5]). [, 3] 47> shuffle: do ([, 5]). [2, 1, 5, 3, 4] 48> shuffle: do ([1, 2, 3, 4, 5]). [3, 1, 2, 4, 5] 49> shuffle: do ([1, 2, 4, 5]). [, 4] 50> shuffle: do ([, 5]). [5, 1, 4, 3, 2] 51> Method 2: The common shuffling algorithm is connected to a List in disorder. I think the original General shuffling algorithm is feasible. I tried to write another function. The test is effective, but I think there is definitely room for optimization. The style of the Code still reveals a strong procedural ideology. % The shuffling algorithm solution [php] do2 (L)-> do2 (L, []). do2 ([], L)-> L; do2 (L1, L2)-> % io: format ("L1 = ~ W L2 = ~ W ~ N ", [L1, L2]), Len = length (L1), if Len> 1-> NL = lists: split (random: uniform (Len-1), L1 ), {[H1 | T1], [H2 | T2]} = NL, NL2 = lists: flatten ([T1], [H1 | T2]), L11 = lists: append (L2, [H2]), do2 (NL2, L11); true-> do2 ([], lists: append (L2, L1) end. the result is: 128> c (shuffle ). {OK, shuffle} 129> shuffle: do2 (lists: seq (0, 9 )). [130,]> shuffle: do2 (lists: seq )). [131,]> shuffle: do2 (li Sts: seq (0, 9 )). [132,]> shuffle: do2 (lists: seq )). [133,]> there are several points worth thinking about whether these two solutions are true shuffling algorithms. Is it equal to the probability that each number appears at a certain position. Other methods are not supported.