MCPcopy Create free account
hub / github.com/gpujs/gpu.js / mathRandomNeverAboveOne

Function mathRandomNeverAboveOne

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

Source from the content-addressed store, hash-verified

63describe('never above 1');
64
65function mathRandomNeverAboveOne(mode) {
66 const gpu = new GPU({ mode });
67 const checkCount = 20;
68 const checkSource = [];
69
70 for (let i = 0; i < checkCount; i++) {
71 checkSource.push(`const check${ i } = Math.random();`);
72 }
73
74 for (let i = 0; i < checkCount; i++) {
75 for (let j = 0; j < checkCount; j++) {
76 if (i === j) continue;
77 checkSource.push(`if (check${i} >= 1) return 1;`);
78 }
79 }
80
81 const kernel = gpu.createKernel(`function() {
82 ${checkSource.join('\n')}
83 return 0;
84 }`, { output: [1] });
85
86 const result = kernel();
87 assert.ok(result.every(value => value === 0));
88}
89
90test('never above 1 every time auto', () => {
91 mathRandomNeverAboveOne();

Callers 1

math.random.jsFile · 0.85

Calls 2

createKernelMethod · 0.95
kernelFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…