您的位置:首页 > 其它

erlang随机排列数组

2016-02-22 00:00 363 查看
参考karl's answer

1> L = lists:seq(1,10). [1,2,3,4,5,6,7,8,9,10]


Associate a random number R with each element X in L by making a list of tuples {R, X}. Sort this list and unpack the tuples to get a shuffled version of L.

2>[X||{_, X} <- lists:sort([{random:uniform(), N} || N <- L])]. [5,2,3,1,7,4,6,9,10,8] 3>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: