procedure choose: set of k integers in [1..n] procedure rand_num: random number generator procedure rand_int: model ?i procedure randomize: randomize procedure randrange: random number in range procedure randrangeseq: random sequence in range procedure randseq: generate &random procedure rng: random number generator procedure shuffle: shuffle
link random
April 11, 2014; Ralph E. Griswold and Gregg M. Townsend
This file is in the public domain.
This file contains procedures related to pseudo-random numbers. choose(k, n) produces a set of k distinct integers in [1..n] rand_num() is a linear congruential pseudo-random number generator. Each time it is called, it produces another number in the sequence and also assigns it to the global variable random. With no arguments, rand_num() produces the same sequence(s) as Icon's built-in random-number generator. Arguments can be used to get different sequences. The global variable random serves the same role that &random does for Icon's built-in random number generator. rand_int(i) produces a randomly selected integer in the range 1 to i. It models ?i for positive i. randomize() sets &random to a "random" value, using /dev/urandom if available, otherwise based on the date and time. randrange(min, max) produces random number in the range min <= i <= max. randrangeseq(i, j) generates the integers from i to j in random order. randseq(seed) generates the values of &random, starting at seed, that occur as the result of using ?x. rng(a, c, m, x) generates a sequence of numbers using the linear congruence method. With appropriate parameters, the result is a pseudo-random sequence. The default values produce the sequence used in Icon. shuffle(x) shuffles the elements of x