The algorithm syntax in the system allows you to generate random numbers in a variety of ways, depending on your requirements and preferences. This table summarizes functions related to random number generation. For a list of Maple™ functions that can be used to generate random numbers, refer to your Maple documentation.
|
Function |
Range of Operation |
Example |
Description |
|
0, ..., n-1 |
rint(3) = 0, 1, or 2 |
Returns a random integer between 0 and n-1 (inclusive). Generates n variations.
| |
|
m, ..., n-1 |
rint(3,6) = 3, 4, or 5 |
Returns a random integer between m and n-1 (inclusive). Generates n-m variations.
| |
|
m, m+k, m+2k, ..., m+q*k (where q is the largest integer such that m+q*k<=n-k) |
rint(3,12,3) = 3, 6, or 9 |
Returns a random integer between m and n-1 (inclusive) in steps of k. Generates approximately (n-m)/k variations.
| |
|
1, ..., n |
range(3) = 1, 2, or 3 |
Returns a random integer between 1 and n (inclusive). Generates n variations.
| |
|
m, ..., n |
range(3,6) = 3, 4, 5, or 6 |
Returns a random integer between m and n (inclusive). Generates (n-m)+1 variations.
| |
|
m, m+k, m+2k, ..., m+q*k (where q is the largest integer such that m+q*k<=n) |
range(3,12,3) = 3, 6, 9, or 12 |
Returns a random integer between m and n (inclusive), in steps of k. Generates approximately (n-m)/k +1 variations.
| |
|
|
m, ..., n |
rand(0.5,9.5) = all real numbers between 0.5 and 9.5 (inclusive) |
Returns a random real number between m and n (inclusive).
|
|
m, ..., n expressed to k significant figures |
rand(0.5,9.5,3) = all real numbers between 0.5 and 9.5 (inclusive), expressed to 3 significant figures |
Returns a random real number between m and n (inclusive), expressed to k significant figures |
See Also:
Tutorial: Algorithmic Question
Tutorial: List-based Variables
Tutorial: Maple-based Algorithmic Question Authoring