LassoScript Utility
Basics Browse Detail

[Math_Random]

Tag Link [Math_Random] Category Math
Type Substitution Source Available No
Support Preferred Version 5.0
Change Unchanged Data Source Any
Output Type Decimal, Integer, or String Security None
Implementation LCAPI Sets Lasso 8.5, Lasso 8.0, Lasso 7.0, Lasso 6.0, Lasso 5.0
Lasso 3 Equivalent [RandomNumber]

Description

[Math_Random] returns a random number. This tag can be used to return a random number between the required -Lower and -Upper parameters inclusive.

If both -Lower and -Upper are integer values then a random integer between them will be returned. The integer can be the -Lower value, -Upper value, or any value in between. If the optional -Hex parameter is specified then the random number will be output in hexadecimal notation.

If either -Lower or -Upper is a decimal value then a decimal value between them will be returned. The precision of the returned decimal value is automatically set to the maximum precision of the -Lower and -Upper parameters, but the value is not rounded.

Note: When returning integer values [Math_Random] can return at most 32-bit values (between approximately +/- 2,000,000,000).

Syntax

[Math_Random: -Lower=Minimum, -Upper=Maximum]

[Math_Random: -Lower=Minimum, -Upper=Maximum, -Hex]

Parameters

Optional Parameters
-Lower The minimum random number to return.
-Upper The maximum random number to return.
-Hex If specified the random number will be returned in hexadecimal format.

Change Notes

Note: Versions of [Math_Random] prior to Lasso 8.0.1 accepted -Min and -Max parameters. The tag would return a value between the minimum value and the maximum value - 1. These parameters are still supported for backward compatibility.

When using -Min and -Max the -Max value is never returned. To get a random sequence of numbers from 0 to N set -Max to N+1. For example, to get a random sequences of numbers from 1 to 6 use [Math_Random: -min=1, -max=7].

Examples

To generate a random HTML color:

Use the [Math_Random] tag to generate three random hexadecimal numbers between 16 and 255. The following code creates a table cell with a random color.

[Variable: 'Color'=(Math_Random-Lower=16, -Upper=255, -Hex) + 
  (Math_Random-Lower =16, -Upper=255, -Hex) + 
  (Math_Random-Lower =16, -Upper=255, -Hex)]
<table border="1" cellpadding="9" cellspacing="0">
  <tr>
    <td bgcolor="#[Variable: 'Color']">
      [Variable: 'Color']
    </td>
  </tr>
</table>

<table>
  <tr>
    <td color="#05D4A1">
      [Variable: 'Color']
    </td>
  </tr>
</table>