WMLScript » Lang » Lang.random

Syntax:
Lang.random(value)
value
The mandatory value parameter can be any positive floating-point number or any positive integer number (including zero) recognized by the browser. Note that zero always returns zero. If a floating-point number is provided, only the integer portion will be used.

Returns a random positive integer.

The Lang.random function generates and returns a pseudo-random positive integer number that is greater than or equal to zero and less than or equal to the given value parameter (i.e., the value parameter sets the upper boundary for the pseudo-random number).

The actual pseudo-random number that is generated will be browser dependent. Unfortunately, many random number generators tend to generate the same repetitive sequence of numbers.

Examples

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>

<card id="card1">
   <p>
   random example
   </p>
   <do type="accept">
      <go href="RandomExample.wmls#findrandom()" />
   </do>
</card>

<card id="card2">
<p>
   random number = $(randomnumber)
</p>
</card>

</wml>
Explanation:

Code for RandomExample.wml

Language(s): WML
Code:
extern function findrandom()
{
   var result = Dialogs.prompt("Enter number", "");
   var randnum = Lang.random(result);
   WMLBrowser.setVar("ramdomnumber", randnum);
   WMLBrowser.go("RandomExample.wml#card2");
};
Explanation:

Code for RandomExample.wmls

Language(s): WML

See Also: