User Tools

Site Tools


en:code:core:algorithms

Algorithms

Common algorithms.

Functions

md4

Calculates a md4 hash.

Syntax

Algorithms.md4(data);

Arguments

  1. 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

  1. 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

  1. 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

  1. 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

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

  1. min - (int) the minimum value
  2. 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

  1. min - (float) the minimum value
  2. 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

  1. 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