uniform(number, number)
uniform(number, number), function
def pure uniform(min: number, max: number): zedfunc
Returns the function $f: k \mapsto \bold 1 (k \in [\text{min},\text{max}])$, that maps $k$ to $1$ if $k \in [\text{min},\text{max}]$ and $0$ otherwise.
The arguments min
and max
must be integers such that min
$\leq$ max
or the function fails.
min
: the start of the interval that the zedfunc will map to 1max
: the end of the interval that the zedfunc will map to 1
Example
show scalar "" a1b2 with uniform(3, 5)
Errors
Calling uniform
with a non-integer argument will fail and return one of the following errors:
‘uniform(min,max)’ is rounding fractional numbers in ‘min’.
‘uniform(min,max)’ is rounding fractional numbers in ‘max’.
Calling uniform
with arguments min
and max
such that min
> max
will fail and return the following error:
‘uniform(min,max)’ has ‘min’ greater than ‘max+1’.
Recipes and best practices
uniform
and its variants can be used as building blocks to craft more complex functions by parts:
// This function maps [0,5] to 1, [6,8] to 2 and [9,+∞] to 3
f = uniform(5) + 2 * uniform(6, 8) + 3 * uniform.right(9)
show scalar "f" a3b4 with f
See also
- uniform disambiguation
- uniform(number)
- uniform.left
- uniform.right
- random.uniform to generate uniform random variables