en:code:core:algorithms
Table of Contents
Algorithms
Common algorithms.
Functions
md4
Calculates a md4 hash.
Syntax
Algorithms.md4(data);
Arguments
- data - (string) the input data
Returns
- (string) the calculated hash in hexadecimal form
Examples
var result = Algorithms.md4("some data"); //result == "a19fcbc49cf40331e8b7873f4700e1fd"
md5
Calculates a md5 hash.
Syntax
Algorithms.md5(data);
Arguments
- data - (string) the input data
Returns
- (string) the calculated hash in hexadecimal form
Examples
var result = Algorithms.md5("some data"); //result == "1e50210a0202497fb79bc38b6ade6c34"
sha1
Calculates a sha1 hash.
Syntax
Algorithms.sha1(data);
Arguments
- data - (string) the input data
Returns
- (string) the calculated hash in hexadecimal form
Examples
var result = Algorithms.sha1("some data"); //result == "baf34551fecb48acc3da868eb85e1b6dac9de356"
setRandomSeed
Set the seed for the pseudorandom number generation.
Syntax
Algorithms.setRandomSeed(seed);
Arguments
- seed - (int) the seed for the pseudorandom number generation
Returns
- (null) nothing
Examples
Algorithms.setRandomSeed(42);
randomMax
Returns the maximum integer value returned by randomInteger.
Syntax
Algorithms.randomMax();
Returns
- (int) the maximum integer value returned by randomInteger
Examples
var result = Algorithms.randomMax();
randomInteger
Returns a random number between 0 and randomMax (inclusive) or between min and max (inclusive).
Syntax
Algorithms.randomInteger();
Algorithms.randomInteger(min, max);
Arguments
- min - (int) the minimum value
- max - (int) the maximum value
Returns
- (int) a random number between 0 and randomMax() (inclusive) or between min and max (inclusive)
Examples
var result = Algorithms.randomInteger();
var result = Algorithms.randomInteger(0, 3);
randomFloat
Return a random decimal (floating) number between min and max (inclusive).
Syntax
Algorithms.randomFloat(min, max);
Arguments
- min - (float) the minimum value
- max - (float) the maximum value
Returns
- (float) a random decimal (floating) number between min and max (inclusive)
Examples
var result = Algorithms.randomFloat(0.15, 3);
randomString
Generates a random string.
Syntax
Algorithms.randomString({object});
Arguments
- object
- characters - (string) character list to choose from (default value: "abcdefghijklmnopqrstuvwxyz0123456789")
- minLength - (int) minimal length (default value: 5)
- maxLength - (int) maximal length (default value: 15)
Returns
- (string) a random string
Exceptions
- (ParameterCountError) incorrect parameter count
Examples
var result1 = Algorithms.randomString(); var result2 = Algorithms.randomString({ characters: "abcdef" }); var result3 = Algorithms.randomString({ characters: "abcdef", minLength: 10, maxLength: 20 });
en/code/core/algorithms.txt · Last modified: 2021/02/13 11:23 by 127.0.0.1