<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -5,11 +5,11 @@
 -module(nglists).
 -export([count/2, deepmap/2, drop/2,
          find_first/2, find_first/3, find_last/2, find_last/3,
-         init/1, pos/2, transpose/1, uniq/1]).
+         init/1, pos/2, transpose/1, uniq/1, shuffle/1, random/1]).
 
 -import(lists, [all/2, append/1, duplicate/2, flatten/1, foldl/3, foreach/2,
-                map/2, nth/2, nthtail/2, reverse/1, seq/2, sum/1, zip/2,
-                zipwith/3]).
+                keysort/2, map/2, nth/2, nthtail/2, reverse/1, seq/2, sum/1, 
+                zip/2, zipwith/3]).
 
 
 %%% @doc  Count the number of list items that satisfy some predicate.
@@ -20,9 +20,9 @@ count(Fun, L) -&gt;
 
 %% @doc Like map, but maintains structure of deep lists.
 
-deepmap(Fun, [H|T]) when list(H) -&gt; [deepmap(Fun, H) | deepmap(Fun, T)];
-deepmap(Fun, [H|T])              -&gt; [Fun(H) | deepmap(Fun,T)];
-deepmap(_Fun, [])                -&gt; [].
+deepmap(Fun, [H|T]) when is_list(H) -&gt; [deepmap(Fun, H) | deepmap(Fun, T)];
+deepmap(Fun, [H|T])                 -&gt; [Fun(H) | deepmap(Fun,T)];
+deepmap(_Fun, [])                   -&gt; [].
 
 
 %% @doc Drop N elements from list L.
@@ -74,7 +74,7 @@ pos(E, [H|_], I) when E == H -&gt; I;
 pos(E, [_|T], I)             -&gt; pos(E, T, I+1).
 
 
-%% @doc Transpose list L.
+%% @doc Transpose list.
 
 transpose(L) -&gt;
     Len = length(hd(L)),
@@ -86,7 +86,23 @@ transpose1([], Acc) -&gt;
     Acc.
 
 
-%% @doc Remove duplicates from list L.
+%% @doc Remove duplicates from list.
 
 uniq([H|T]) -&gt; [H | uniq([Y || Y &lt;- T, Y =/= H])];
 uniq([])    -&gt; [].
+
+
+%% @doc Shuffle list.
+
+%% Knuth shuffle.
+shuffle(L) -&gt;
+    N = length(L) * 10000,
+    Pairs = map(fun(X) -&gt; {random:uniform(N), X} end, L),
+    Sorted = keysort(1, Pairs),
+    map(fun({_, X}) -&gt; X end, Sorted).
+    
+
+%% @doc Return an element from the list picked randomly.
+
+random(L) -&gt;
+    nth(random:uniform(length(L)), L).
\ No newline at end of file</diff>
      <filename>nglists.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>675b7328ad09b7de82422105c440f23b58d71d6f</id>
    </parent>
  </parents>
  <author>
    <name>Hasan Veldstra</name>
    <email>hasan.veldstra@gmail.com</email>
  </author>
  <url>http://github.com/hassy/ngerl/commit/04f34b461a09406ee47a2b87f3a35b20b047a7a9</url>
  <id>04f34b461a09406ee47a2b87f3a35b20b047a7a9</id>
  <committed-date>2009-06-28T06:31:16-07:00</committed-date>
  <authored-date>2009-06-28T06:31:16-07:00</authored-date>
  <message>Add functions shuffle() and random()</message>
  <tree>c71819495fbc1f8290666c1e955d9033ae3525fd</tree>
  <committer>
    <name>Hasan Veldstra</name>
    <email>hasan.veldstra@gmail.com</email>
  </committer>
</commit>
