aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-06-23 22:07:54 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-06-23 22:17:43 -0400
commit1955e7b13a459c08a080782140e53e0d9c6386b1 (patch)
treefbb967c588a335576ca624ee9fe35e3a95dc1170
parent47c01507e28cb01974a335542f01689c93db71ee (diff)
Actually no need for Vitter if you can sort
-rw-r--r--test/fuzz.bqn41
1 files changed, 2 insertions, 39 deletions
diff --git a/test/fuzz.bqn b/test/fuzz.bqn
index 999aeb79..1a3e95fc 100644
--- a/test/fuzz.bqn
+++ b/test/fuzz.bqn
@@ -53,45 +53,8 @@ RandRank ← 4 _randUnbounded
Sigmoid ← (40≤|)◶⟨1(-÷+)˜⋆,×⟩
-# Generate 𝕨 positive (not zero) integers summing to 𝕩
-RandPart ← {k←𝕨 ⋄ n←𝕩
- RU ← Range∘0 # Random float in [0,1]
- # Vitter, "An Efficient Algorithm for Sequential Random Sampling"
- vPrime ← @
-
- # Add or reject each possibility individually
- MethodA ← {k←𝕩
- v ← RU@
- 1 { (𝕨×-⟜k⊸÷n-𝕩) (⊣𝕊1+⊢)⍟(v<⊣) 𝕩 } 0
- }
-
- # Compute number of skipped possibilities
- MethodD ← {k←𝕩
- RvP ← k√RU # Generate new vPrime
- kn ← k-1 # k for next iteration
- qu1 ← n-kn
- Sk ← {vP←𝕩
- s ← ⌊ x ← { 𝕊∘RvP⍟(qu1⊸≤) n׬𝕩 } vP
- y1 ← kn √ (n ÷ qu1) × RU@
- vPrime ↩ y1 × (1-x÷n) × qu1 (⊣÷-) s
- Cont ← {
- y2 ← ×´ kn (((n-1)-↕∘⌊) (⊣÷-) ⌈) 𝕩
- (n(⊣÷-)x) < y1 × kn√y2
- }
- Cont◶⟨{ vPrime↩@ ⋄ 𝕩 }, 𝕊 RvP⟩⍟(1<vPrime) s
- }
- Sk RvP⍟(@⊸≡) vPrime
- }
-
- Gen ← {𝕤
- alphaInv ← 13 # Used to choose A or D
- M ← {n≤alphaInv×𝕩}◶MethodD‿{vPrime↩@ ⋄ (M↩MethodA)𝕩}
- seq ← { n-↩1+s←M𝕩 ⋄ s }¨ k-↕k-1
- last ← ⌊n×RU⍟(@⊸≡)vPrime
- 1 + seq ∾ last
- }
- 0⊸<◶↕‿Gen k
-}
+# 𝕨 positive (not zero) integers summing to 𝕩
+RandPart ← { ¬⟜» (𝕨-1) (∧∘Rand∾1-˜⊢) 𝕩¬𝕨 }
# 𝕩 is maximum bound plus 1 for both functions
⟨RandBound,RandShape⟩ ← {