# Use Randomized Numbers

You can use the WebAssign randnum() function in your questions to generate randomized integer values within a specified range. If needed, you can use the randomized integer values to compute decimal or fractional values.

Best Practice Assign each randomized value to a variable. Then use the variable to perform additional computation or to display the value in the question, answer key, or solution.
1. If needed, open your question in the Question Editor.
2. In an <EQN> or <eqn> tag, use the randnum() function to generate a randomized integer.

If needed, calculate a decimal or fractional value using the randomized integer.

Use the following syntax:

randnum(low, high, increment, exclude)
where:
• low and high are integers defining the smallest and greatest values to be returned by the function.
• increment is a natural number defining the interval of values to be returned between low and high.
• exclude is an optional single value that should not be returned. One reason to use this is to prevent a problem from using the same values as an example in the textbook.
Note Ensure that the value you are excluding is one that might otherwise be returned. For example, in the following code, $a is never excluded because$a is one of (1,3,5,7,9) and $b can never be any of those values. $a = randnum(1,9,2);
$b = randnum(2,10,2,$a);

For example:

# an integer between 1 and 8:
$a = randnum(1,8,1); # an even number between 20 and 50:$b = randnum(20,50,2);

# an integer between 1 and 9 ≠ $a:$c = randnum(1,9,1,$a); # a multiple of 0.25 between 1.50 and 2.50:$d = decform(randnum(150,250,25)/100,2)

# a multiple of 1/6 between 3 and 4, as a reduced
# fraction (3, 19/6, 10/3, 7/2, 11/3, 23/6, 4):
$e = fraction(randnum(18,24,1),6) ## Example Numerical Question With Randomized Values The following table summarizes an actual question.  QID 1870653 Template2 numerical_randomization Numerical $minutes = randnum(3,8,1); $mph = randnum(30,90,6,60);$mpm = $mph / 60;$distance = $mpm *$minutes; '' How many miles will a car travel in minutes if its speed is constant at mph?
<_> miles  Since there are 60 minutes/hour, at mph the car is traveling at miles/minute.