| Package | com.godpaper.as3.utils |
| Class | public class MathUtil |
| Inheritance | MathUtil Object |
| Method | Defined 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 | ||
| factorial | () | method |
public static function factorial(n:Number):NumberComputes the factorial of parameter n.
Parameters
n:Number — the number
|
Number — the factorial of n
|
| intXORrandom | () | method |
public static function intXORrandom():NumberUsing 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();
ReturnsNumber — 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
|
Array — kth permutation of order n
|
| permutation | () | method |
public static function permutation(n:Number, k:Number):Array
Parameters
n:Number — Order
| |
k:Number — Factoradic
|
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.
|
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.
|
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.
|
Array — all of posibilities of the premutated number with picked elements.
|
| toFactoradic | () | method |
public static function toFactoradic(n:Number):Arraylogic (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
|
Array — Factoradic representation of integer k as an Array
|
| toFactoradic2 | () | method |
public static function toFactoradic2(n:Number, k:Number):ArrayThis function can be used with a permutation generator.
Parameters
n:Number — positive integer to represent
| |
k:Number — factoradic length
|
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.
|
Number — postive number.
|
| transactDiffRandomNumberInRange | () | method |
public static function transactDiffRandomNumberInRange(min:Number, max:Number):Number
Parameters
min:Number | |
max:Number |
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.
|
Number — the random number between min and max.
|
| uintXORrandom | () | method |
public static function uintXORrandom():NumberUsing 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();
ReturnsNumber — random number between 0~1.
|