Welcome! Please see the About page for a little more info on how this works.

0 votes
in core.async by
In cljs, {{clojure.core.async/random-array}}'s shuffle was incorrect, leading it to always return \[1 0\] for arg n=2. This breaks the promise that alts! is non-deterministic w.r.t. op selection by always trying the second element first. Additionally, the first op is never chosen first for alts! of any size N>1.

Use goog.array.shuffle to do the shuffle instead. (This API is also used by cljs.core/shuffle)

New implementation passes tests and behaves better:

{code:java}

cljs.user=> (frequencies (take 10000 (map vec (repeatedly #(a/random-array 2)))))
WARNING: var: cljs.core.async/random-array is not public at line 1 <cljs repl>
{[0 1] 4964, [1 0] 5036}

cljs.user=> (frequencies (take 10000 (map vec (repeatedly #(clojure.core.async/random-array 3)))))
WARNING: var: cljs.core.async/random-array is not public at line 1 <cljs repl>
{[0 1 2] 1720, [1 2 0] 1679, [2 0 1] 1669, [0 2 1] 1573, [1 0 2] 1682, [2 1 0] 1677}
cljs.user=> (pp)
{[0 1 2] 1720,
 [1 2 0] 1679,
 [2 0 1] 1669,
 [0 2 1] 1573,
 [1 0 2] 1682,
 [2 1 0] 1677}
nil

3 Answers

0 votes
by

Comment made by: mfikes

ASYNC-227.patch LGTM (y)

0 votes
by

Comment made by: gshayban

fixed in 14bed8383516ab119c3fc51c2882112000eb5664 , 0.4.500

0 votes
by
Reference: https://clojure.atlassian.net/browse/ASYNC-227 (reported by gshayban)
...