www.webdeveloper.com
Results 1 to 2 of 2

Thread: random methog/math object

  1. #1
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    1

    Question random methog/math object

    how can i use the random method for a range of numbers not starting at zero? like: 10<=n<=20, or -3<=n<=11.

    is this the right/only way (for example one)?

    <script type="text/javascript">
    noUnrounded=Math.random()*10;
    noRounded=Math.round(noUnrounded+10);
    document.writeln(noRounded);
    </script>

    Thanks, appreciate it.

  2. #2
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    Code:
    /*
     * rand()      0 <= n < 1
     * rand(10)    0 <= n < 10
     * rand(4,10)  4 <= n < 10
     */
    function rand()
    {
        var lower = 0;
        var upper = 1;
        
        if (arguments.length == 1)
            upper = arguments[0];
        else if (arguments.length == 2) {
            lower = arguments[0];
            upper = arguments[1];
        }
        
        return Math.random() * (upper - lower) + lower;
    }
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles