forked from uillianluiz/node-tiers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.ts
51 lines (42 loc) · 1.52 KB
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { _ } from 'underscore';
import math = require('mathjs');
export default class Util {
public static arraysLength = 10000000;
public static matrixSize = 300;
public static sortedArray = _.range(Util.arraysLength);
public static unsortedArray = _.shuffle(_.range(Util.arraysLength));
public static randomStringMap = new Map<number, string>();
/**
* Function that generates a random number that works as input to the search algorithms.
*/
public static randomNumber(): number{
return _.random(0, Util.arraysLength);
}
/**
* Generates a random string
* @param length size of the generated random string
*/
public static randomString(length: number) {
if(this.randomStringMap.has(length)){
return this.randomStringMap.get(length);
}
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++) {
text += possible.charAt(_.random(0, possible.length));
}
this.randomStringMap.set(length, text);
return text;
}
/**
* Generates a random matrix using the mathjs library
* @param m number of columns
* @param n number of rows
*/
public static randomMatrix(m = this.matrixSize, n = this.matrixSize){
return math.random([m, n]);
}
public static randomVector(m = this.matrixSize){
return math.random([m]);
}
}