Defining variables using random numbers is the basis of creating algorithmic variations. The basic Scientific Notebook random number function is called rand. When the insertion point is in mathematics and you type the function name, Scientific Notebook automatically recognizes the function and displays it on your screen in gray letters. (More information about using mathematical functions in Scientific Notebook is available online via the Help ContentsContents.tex.) You can combine random number functions with definitions to gain a powerful algorithmic tool.
The
rand function has four forms:
itbpF43.125pt18.5pt4ptex3.wmf
rand() might yield a number such as
427419669081,
321110693270, or
.
itbpF43.125pt18.5pt4ptex3.wmf
rand(10) produces one of these numbers: 1, 2, 3, 4, 5, 6, 7, 8,
or 9.
itbpF43.125pt18.5pt4ptex3.wmf
rand(2, 7) produces one of these numbers: 2, 3, 4, 5, 6, or 7.
itbpF43.125pt18.5pt4ptex3.wmf
rand({2, 4, 6, 8}) produces one of these numbers: 2, 4, 6, or 8.
This form of the function can also be used with expressions. The function
rand({sin x, cos x}) randomly selects either sin x or cos x.
An additional random number function, called randmat, produces random matrices of various types. The function has this form:
where
a is the number of matrix rows,
b is the number of matrix columns,
c is the matrix type, with
1 = arbitrary
2 = symmetric (must be square)
3 = antisymmetric (must be square)
4 = unimodular and
d
is the selection range for the values in the matrix:
The range (n), with n as a single positive integer, produces matrix values between 0 and n - 1.
The range (n, m), where n < m, produces matrix values between n and m, inclusive.
The range ({some set}) produces matrix values selected at random from the specified set.
itbpF43.125pt18.5pt4ptex3.wmfThe function
randmat
4, 4, 1,
1, 9
produces a 4×4 arbitrary matrix whose values are between 1 and 9,
inclusive. Here's an example: