All files / tests / js_denotest / test-util / rand_f32a.js

100.00% Branches 0/0
100.00% Lines 23/23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x3
x22
x22
x22
x22




















/**
 * @file Generate a random `Float32Array`
 *
 * Note: It has no tests. Because it's very simple code (so test unnecessary), and testing for random is difficult.
 *
 * @author aKuad
 */


/**
 * Generate a random `Float32Array`
 *
 * It can use for test data as random audio.
 *
 * @param {number} elem_count Length of array to generate
 * @returns {Float32Array} Random array
 */
export function generate_rand_float32array(elem_count) {
  return Float32Array.from(new Array(elem_count), () => (Math.random() - 0.5) * 2);
  // - 0.5   --> Random number range is [ -0.5, 0.5)
  // * 2     -->                        [   -1,   1)
}