FUNCTION:  Lang.seed

Lang.seed(value)
 
The Lang.seed function is used to initialize the pseudo-random number generating sequence. This is referred to as seeding the random number sequence. Unfortunately, many random number generators tend to generate the same repetitive sequence of numbers. The purpose of the seed is to make the generated number more random.
 
Be aware that the actual pseudo-random number that is generated will be browser dependent.
 
The mandatory value parameter can be any positive or negative integer number (including zero) recognized by the browser. If a floating-point number is provided, only the integer portion will be used.
 
  • If the seed is zero or a positive integer, then the provided seed value is used and a repeatable sequence of pseudo-random numbers will be generated.

  •  
  • If the seed is a negative integer, then the provided seed value is not used and, instead, a system-generated initialization value will be used.

  •  
    Code for SeedExample.wml
    <?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>
       seed example
       </p>
       <do type="accept">
          <go href="SeedExample.wmls#findseed()" />
       </do>
    </card>

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

    </wml>

     
    Code for SeedExample.wmls
    extern function findseed()
    {
       var myseed = Dialogs.prompt("Enter seed number", "-6");
       Lang.seed(myseed);
       var randnum = Lang.random(1000);
       WMLBrowser.setVar("myseed", myseed);
       WMLBrowser.setVar("ramdomnumber", randnum);
       WMLBrowser.go("SeedExample.wml#card2");
    };


    Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
    Trademark Information