You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
941 B
31 lines
941 B
class Generator {
|
|
/**
|
|
* Create a new generator
|
|
* @param {number} dimensions - The number of dimensions for the random vectors
|
|
*/
|
|
constructor(dimensions) {
|
|
this.dimensions = dimensions;
|
|
}
|
|
|
|
/**
|
|
* Generates a random vector with the specified number of dimensions.
|
|
* Each element of the vector is a random number between 0 and 1.
|
|
* @returns {number[]} A random vector of the given dimensions
|
|
*/
|
|
generate() {
|
|
return Array.from({ length: this.dimensions }, () => Math.random());
|
|
}
|
|
|
|
/**
|
|
* Generates an array of a specified length, each element of which is a
|
|
* random vector of the given dimension.
|
|
* @param {number} count - The number of vectors to generate
|
|
* @returns {number[][]} an array of random vectors
|
|
*/
|
|
generateMany(count) {
|
|
return Array.from({ length: count }, () => this.generate());
|
|
}
|
|
}
|
|
|
|
module.exports = Generator;
|