diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-08-19 07:55:22 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-08-19 07:55:22 -0400 |
| commit | 222a7f19b75388b0c07b339ada198eb8fe5b9b15 (patch) | |
| tree | 90272b06159a63e8cdadf65767af5c192158cbc1 /spec/system.md | |
| parent | d9546b5085d95696e93b2796545ff94eafe05928 (diff) | |
Specify β’MakeRand and β’rand
Diffstat (limited to 'spec/system.md')
| -rw-r--r-- | spec/system.md | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/system.md b/spec/system.md index 041b4539..adfbcfd5 100644 --- a/spec/system.md +++ b/spec/system.md @@ -198,3 +198,21 @@ The [Unix epoch](https://en.wikipedia.org/wiki/Unix_time) is 1970-01-01 00:00:00 `β’_timed` returns the total time taken divided by the number of function calls (`π¨` if provided and 1 otherwise), including the overhead required for the outer loop that counts iterations (which will typically be negligible in comparison to the BQN code). More accurately the modifier `β’_maxTime_` *may* fail if execution of `π½` takes over `π¨πΎπ©` seconds, and should fail as quickly as it is practically able to. The most likely way to implement this modifier is to interrupt execution at the given time. If `π½` completes before the interrupt there is no need to measure the amount of time it actually took. + +## Random generation + +`β’MakeRand` initializes a deterministic pseudorandom number generator with seed value `π©`. `β’rand`, if it exists, is a globally accessible generator initialized at first use. A random generator has the following member functions: + +| Name | Summary +|-----------|------------------------------ +| `Range` | An array of shape `π¨β£β¨β©` selected from `βπ©` +| `Deal` | A simple random sample of `π¨β£π©` elements of `βπ©` +| `Subset` | A sorted SRS of `π¨` elements of `βπ©` + +For each of these functions, `π©` is a natural number. For `Range`, `π¨` must be a valid shape if given, and for `Deal` and `Subset` it's a natural number less than or equal to `π©`. All selections are made uniformly at random, that is, each possible result is equally likely. A simple random sample (SRS) of `k` elements from list `s` is a list of `k` distinct elements of `s` in any order. Both the choice of elements and their ordering must be uniformly random. [Recommended algorithms](../implementation/primitive/random.md#simple-random-sample) for SRS selection are variants of a partial Knuth shuffle. + +When `π¨` isn't given, `Deal`'s result contains all elements of `βπ©`, making it a random shuffle of those values, or random permutation. In `Subset`, setting `π¨` to `π©` would instead always result in the list `βπ©`; because this is not useful, `π¨` must be provided. + +In `Range`, `π©` may be `0`. In this case the result consists of floating-point numbers in the unit interval from 0 to 1. The numbers should have an overall uniform distribution, but their precision and whether the endpoints 0 and 1 are possible may depend on the implementation. + +Ranges up to `2β32` must be supported (that is, a maximum integer result of `(2β32)-1`) if the number system accommodates it. In implementations based on double-precision floats it's preferable but not required to support ranges up to `2β53`. |
