MCPcopy Index your code
hub / github.com/gpujs/gpu.js / mathRandomUnique

Function mathRandomUnique

test/internal/math.random.js:7–41  ·  view source on GitHub ↗
(mode)

Source from the content-addressed store, hash-verified

5describe('Math.random() unique');
6
7function mathRandomUnique(mode) {
8 const gpu = new GPU({ mode });
9 const checkCount = 20;
10 let seed1 = Math.random();
11 let seed2 = Math.random();
12 let stub = sinon.stub(mathRandom, 'onBeforeRun').callsFake((kernel) => {
13 kernel.setUniform1f('randomSeed1', seed1);
14 kernel.setUniform1f('randomSeed2', seed2);
15 });
16 try {
17 gpu.addNativeFunction('getSeed', `highp float getSeed() {
18 return randomSeedShift;
19 }`);
20 const kernel = gpu.createKernel(function () {
21 const v = Math.random();
22 return getSeed();
23 }, {output: [1]});
24 const results = [];
25 for (let i = 0; i < checkCount; i++) {
26 const result = kernel();
27 assert.ok(results.indexOf(result[0]) === -1, `duplication at index ${results.indexOf(result[0])} from new value ${result[0]}. Values ${JSON.stringify(results)}`);
28 results.push(result[0]);
29 seed2 = result[0];
30 assert.ok(stub.called);
31 stub.restore();
32 stub.callsFake((kernel) => {
33 kernel.setUniform1f('randomSeed1', seed1);
34 kernel.setUniform1f('randomSeed2', seed2);
35 });
36 }
37 } finally {
38 stub.restore();
39 gpu.destroy();
40 }
41}
42
43test('unique every time auto', () => {
44 mathRandomUnique();

Callers 1

math.random.jsFile · 0.85

Calls 5

addNativeFunctionMethod · 0.95
createKernelMethod · 0.95
destroyMethod · 0.95
kernelFunction · 0.85
setUniform1fMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…