home *** CD-ROM | disk | FTP | other *** search
/ Ice Age Fan CD 1 / CD1_Scrat.iso / flash / data / game.swf / scripts / com / terry / SeededRandomNumber.as < prev    next >
Encoding:
Text File  |  2012-07-04  |  916 b   |  42 lines

  1. package com.terry
  2. {
  3.    public class SeededRandomNumber
  4.    {
  5.       public var seed:uint;
  6.       
  7.       public function SeededRandomNumber()
  8.       {
  9.          super();
  10.          seed = 1;
  11.       }
  12.       
  13.       public function nextInt() : uint
  14.       {
  15.          return gen();
  16.       }
  17.       
  18.       public function nextDouble() : Number
  19.       {
  20.          return gen() / 2147483647;
  21.       }
  22.       
  23.       public function nextIntRange(param1:Number, param2:Number) : uint
  24.       {
  25.          param1 -= 0.4999;
  26.          param2 += 0.4999;
  27.          return Math.round(param1 + (param2 - param1) * nextDouble());
  28.       }
  29.       
  30.       public function nextDoubleRange(param1:Number, param2:Number) : Number
  31.       {
  32.          return param1 + (param2 - param1) * nextDouble();
  33.       }
  34.       
  35.       private function gen() : uint
  36.       {
  37.          return seed = seed * 16807 % 2147483647;
  38.       }
  39.    }
  40. }
  41.  
  42.