aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2018-12-03 23:35:02 -0400
committerEduardo Julian2018-12-03 23:35:02 -0400
commit7fab6e42fb986b1d66a6ab9cdf822f429224a3d3 (patch)
tree27731ea07b13738b160dd0126c4f18b999b5b283
parent3da30aff80bc8c80e090574887a58c6015ceb694 (diff)
Excised contribution relevant to this: https://github.com/LuxLang/lux/pull/35
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/math/random.lux21
-rw-r--r--stdlib/test/test/lux/math/random.lux11
2 files changed, 1 insertions, 31 deletions
diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux
index ffb7bc592..b73e7df02 100644
--- a/stdlib/source/lux/math/random.lux
+++ b/stdlib/source/lux/math/random.lux
@@ -293,24 +293,3 @@
(i64.xor (i64.left-shift 14 s01)))
(i64.rotate-left 36 s01)]))
("lux i64 +" s0 s1)]))
-
-(def: (swap from to vec)
- (All [a] (-> Nat Nat (Row a) (Row a)))
- (|> vec
- (row.put to (maybe.assume (row.nth from vec)))
- (row.put from (maybe.assume (row.nth to vec)))))
-
-(def: #export (shuffle seed row)
- {#.doc "Shuffle a row randomly based on a seed value."}
- (All [a] (-> Nat (Row a) (Row a)))
- (let [_size (row.size row)
- _shuffle (monad.fold Monad<Random>
- (function (_ idx vec)
- (do Monad<Random>
- [rand nat]
- (wrap (swap idx (n/% _size rand) vec))))
- row
- (list.indices _size))]
- (|> _shuffle
- (run (pcg-32 [123 seed]))
- product.right)))
diff --git a/stdlib/test/test/lux/math/random.lux b/stdlib/test/test/lux/math/random.lux
index f3f118c90..a7f126ef3 100644
--- a/stdlib/test/test/lux/math/random.lux
+++ b/stdlib/test/test/lux/math/random.lux
@@ -28,11 +28,7 @@
_set (r.set number.Hash<Nat> size r.nat)
_dict (r.dictionary number.Hash<Nat> size r.nat r.nat)
top r.nat
- filtered (|> r.nat (r.filter (n/<= top)))
- shuffle-seed r.nat
- #let [sorted (|> _row row.to-list (list.sort n/<))
- shuffled (|> sorted row.from-list (r.shuffle shuffle-seed))
- re-sorted (|> shuffled row.to-list (list.sort n/<))]]
+ filtered (|> r.nat (r.filter (n/<= top)))]
($_ seq
(test "Can produce lists."
(n/= size (list.size _list)))
@@ -50,9 +46,4 @@
(n/= size (dict.size _dict)))
(test "Can filter values."
(n/<= top filtered))
- (test "Can shuffle rows."
- (let [(^open "v/.") (row.Equivalence<Row> number.Equivalence<Nat>)
- sorted (row.from-list sorted)]
- (and (not (v/= sorted shuffled))
- (v/= sorted (row.from-list re-sorted)))))
))))