initurn
initurn(
@size 10
@id 0
@offset 1
@useseed 0
) -> null
Given a size and a URN identifier, it initializes a new unique random number generator (URN). Once initialized, the identifier can be used to generate unique random numbers via the urn function. This allows for independent URNs of different sizes to be used within the same script. If a URN associated with the identifier already exists, the URN is reset. The initialized URN can be optionally seeded. See setseed.
Arguments
@size[int]: Number of unique random numbers. (default:10).@id[int/float/symbol]: Identifier for unique random number generator. (default:0).@offset[int/float]: Value by which to offset generated numbers. (default:1).@useseed[list/llll]: Use random seed for URN associated with@id. (default:0).0: Off1: On
Usage
$nums = 1 5 10 15 20;
$x = 11.2;
$match = nearest(@list $nums @target $x);
$matchid = nearest(@list $nums @target $x @mode 1); ## return index instead
print($match $matchid) ## 10 3