aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-10-06 11:34:10 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-10-06 11:34:10 -0400
commit2ce2dc40702431ef3d3ffece9e2f6f8b883ac6c5 (patch)
tree9c00897e15952eb5a02e58358383a57355d6f72c /docs
parent0745f57691ea59f91155b2a014be80529b97701f (diff)
Support list 𝕨 (arbitrary shape) for β€’rand.Range
Diffstat (limited to 'docs')
-rw-r--r--docs/bqn.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/docs/bqn.js b/docs/bqn.js
index fbbea582..aa630539 100644
--- a/docs/bqn.js
+++ b/docs/bqn.js
@@ -587,7 +587,14 @@ let rand = (() => {
let range = (x,w) => {
reqnat("Range: 𝕩", x);
let r = x ? (()=>randnat(x)) : Math.random;
- return has(w) ? list(Array(w).fill().map(r)) : r();
+ if (!has(w)) return r();
+ let n = 1;
+ if (!w.sh) reqnat("Range: 𝕨", n=w);
+ else {
+ if (w.sh.length!==1) throw Error("Range: array 𝕨 must have rank 1");
+ w.map(m => {reqnat("Range: 𝕨 element", m); n*=m;});
+ }
+ return arr(Array(n).fill().map(r), w.sh?w:[m], 0);
};
let iota = x => Array(x).fill().map((_,i)=>i);
let deal_err = e => (x,w) => {