6.17 Generating Random Numbers in Questions - Maple T.A. 2016 Help

# Maple T.A. Online Help

Instructor
Select your version: Maple T.A. 2017 | Maple T.A. 2016 | Maple T.A. 10

## 6.17 Generating Random Numbers in Questions

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.

Table 6.12: Random Number Generators

Function

Range of Operation

Example

Description

`rint(n)`

0, ..., n-1

rint(3)

= 0, 1, or 2

Returns a random integer between 0 and n-1 (inclusive). Generates n variations.

`rint(m,n)`

m, ..., n-1

`rint(3,6)`

= 3, 4, or 5

Returns a random integer between m and n-1 (inclusive). Generates n-m variations.

`rint(m,n,k)`

m, m+k, m+2k, ..., m+q*k (where q is the largest integer such that )

`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.

`range(n)`

1, ..., n

`range(3)`

= 1, 2, or 3

When n is a positive integer, returns a random integer between 1 and n (inclusive). Generates n variations.

`range(m,n)`

m, m+1,... ,m+q (where q is the floor of (n-m)/k)

range(3,6)

= 3, 4, 5, or 6

Returns a random integer between m and n (inclusive). Generates (n-m)+1 variations.

`range(m,n,k)`

)

`range(3,12,3) `

= 3, 6, 9, or 12

Returns a random number between m and n (inclusive), in steps of k. Generates approximately (n-m)/k +1

variations.

```rand(m,n)
```

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).

`rand(m,n,k)`

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

For details on each of these functions, see Functions and Arguments.

In addition to Maple T.A.'s built-in functions, you can access MapleTM commands. Maple provides many randomization commands. The following table lists selected randomization commands in Maple. For more information on Maple functions that can be used to generate random numbers, refer to your Maple documentation.

Table 6.13: Maple Randomization Commands

Maple Function

Use

rand

generate a random 12-digit non-negative integer, or a random integer within a specified range (inclusive)

randpoly

random polynomial generator

LinearAlgebra[RandomMatrix]

construct a random Matrix

LinearAlgebra[RandomVector]

construct a random Vector

RandomTools[Generate]

generate a particular random object (For example, return a random complex number with real and imaginary parts of a specified flavor, or choose one of the entries in a collection with equal probability)

Note: When using Maple's random number generator rand, you must include randomize(): as the first part of the call. This sets the initial state of the random number generator using a number based on the system clock instead of the default seed in Maple. Without randomize(), each call to rand will produce the same sequence of values using the default randomization seed. For an example that uses Maple randomization commands, see Tutorial: Maple-based Algorithmic Question Authoring.

See Also:

Tutorial: Algorithmic Question

Tutorial: List-based Variables

Tutorial: Maple-based Algorithmic Question Authoring