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.

How-ToInstructor HelpWebAssign
  1. If needed, open your question in the Question Editor.

    Some questions are not searchable because of their Permission settings.

    If

    Do this

    You know the question ID or name

    1. In the search box at the top of the page, select Question.
    2. Type the question name or ID and press Enter.

    You own the question

    1. Click Questions My Questions.
    2. Click the question name.

    You organize your questions in folders

    1. Click Assignments Folders and navigate to the folder with the question.
    2. Click the question name.

    You want to use advanced search

    1. Click Questions Search Questions.
    2. Enter the search criteria you want to use.

      To view only your questions, click me next to Author.

    3. Click Search.
    4. If you own the question, click Edit next to your question.

      If you do not own the question, click View, then click Open in Editor under Previewer Tools.

  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.

    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 Name Template2 numerical_randomization Mode Numerical Question <eqn> $minutes = randnum(3,8,1); $mph = randnum(30,90,6,60); $mpm = $mph / 60; $distance = $mpm * $minutes; '' </eqn> How many miles will a car travel in <eqn $minutes> minutes if its speed is constant at <eqn $mph> mph? <br> <_> miles Answer <EQN $size=2; $distance> Solution Since there are 60 minutes/hour, at <eqn $mph> mph the car is traveling at <eqn $mpm> miles/minute. Display to Students