Packagecom.godpaper.as3.utils
Classpublic class MathUtil
InheritanceMathUtil Inheritance Object

Permutation Utility class version 1. Copyright (c) 2008 H. Melih Elibol Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. / /



Public Methods
 MethodDefined By
  
factorial(n:Number):Number
[static] Computes the factorial of parameter n.
MathUtil
  
intXORrandom():Number
[static] Using XOR algorithm with integer, primarily because AS3 is lightning-quick with bit operations, and the algorithm is only 4 lines of code.
MathUtil
  
permutateArray(n:Array, k:Number):Array
[static]
MathUtil
  
permutation(n:Number, k:Number):Array
[static]
MathUtil
  
premutate(n:Number, r:Number):Number
[static]
MathUtil
  
randomPremutate(n:Array, r:Number):Array
[static]
MathUtil
  
randomPremutates(n:Array, r:Number, s:Boolean = true):Array
[static]
MathUtil
  
toFactoradic(n:Number):Array
[static] logic (lsd = least significant digit): j++; //move to next digit n/=(j-1); //move "decimal place" of n (this is to create the next lsd) by previous base j-1, which does not move (since j is 1) Number(n)%j; //get the lsd of n in base j
MathUtil
  
toFactoradic2(n:Number, k:Number):Array
[static] This function can be used with a permutation generator.
MathUtil
  
transactAbs(value:Number):Number
[static]
MathUtil
  
transactDiffRandomNumberInRange(min:Number, max:Number):Number
[static]
MathUtil
  
transactRandomNumberInRange(min:Number, max:Number):Number
[static]
MathUtil
  
uintXORrandom():Number
[static] Using XOR algorithm with un-integer, primarily because AS3 is lightning-quick with bit operations, and the algorithm is only 4 lines of code.
MathUtil
Method Detail
factorial()method
public static function factorial(n:Number):Number

Computes the factorial of parameter n.

Parameters

n:Number — the number

Returns
Number — the factorial of n
intXORrandom()method 
public static function intXORrandom():Number

Using XOR algorithm with integer, primarily because AS3 is lightning-quick with bit operations, and the algorithm is only 4 lines of code. Notice: it is 2 time faster than Math.random();

Returns
Number — random number between 0~1.
permutateArray()method 
public static function permutateArray(n:Array, k:Number):Array

Parameters

n:Array — Order as an array
 
k:Number — Factoradic

Returns
Array — kth permutation of order n
permutation()method 
public static function permutation(n:Number, k:Number):Array

Parameters

n:Number — Order
 
k:Number — Factoradic

Returns
Array — kth permutation of order n
premutate()method 
public static function premutate(n:Number, r:Number):Number

Parameters

n:Number — number of blanket elements.
 
r:Number — number of picking elements from blanket.

Returns
Number — the premutated number with picked elements.
randomPremutate()method 
public static function randomPremutate(n:Array, r:Number):Array

Parameters

n:Array — number of blanket elements.
 
r:Number — number of picking elements from blanket.

Returns
Array — one of posibilities of the premutated number with picked elements.
randomPremutates()method 
public static function randomPremutates(n:Array, r:Number, s:Boolean = true):Array

Parameters

n:Array — number of blanket elements.
 
r:Number — number of picking elements from blanket.
 
s:Boolean (default = true) — whether the picked elements is successional.

Returns
Array — all of posibilities of the premutated number with picked elements.
toFactoradic()method 
public static function toFactoradic(n:Number):Array

logic (lsd = least significant digit): j++; //move to next digit n/=(j-1); //move "decimal place" of n (this is to create the next lsd) by previous base j-1, which does not move (since j is 1) Number(n)%j; //get the lsd of n in base j

Parameters

n:Number — positive integer to represent

Returns
Array — Factoradic representation of integer k as an Array
toFactoradic2()method 
public static function toFactoradic2(n:Number, k:Number):Array

This function can be used with a permutation generator.

Parameters

n:Number — positive integer to represent
 
k:Number — factoradic length

Returns
Array — Factoradic representation of integer k as an Array
transactAbs()method 
public static function transactAbs(value:Number):Number

Parameters

value:Number — wheather negative or postive number.

Returns
Number — postive number.
transactDiffRandomNumberInRange()method 
public static function transactDiffRandomNumberInRange(min:Number, max:Number):Number

Parameters

min:Number
 
max:Number

Returns
Number — the random number between min and max but diff from previous result.
transactRandomNumberInRange()method 
public static function transactRandomNumberInRange(min:Number, max:Number):Number

Parameters

min:Number — minium of random ranges.
 
max:Number — maxium of random ranges.

Returns
Number — the random number between min and max.
uintXORrandom()method 
public static function uintXORrandom():Number

Using XOR algorithm with un-integer, primarily because AS3 is lightning-quick with bit operations, and the algorithm is only 4 lines of code. Notice: it is 4 time faster than Math.random();

Returns
Number — random number between 0~1.