Skip to content

Commit

Permalink
Switch memory model tests to use PRNG (#3391)
Browse files Browse the repository at this point in the history
* Switch to PRNG from Math.random
* update comments
  • Loading branch information
alan-baker authored Feb 13, 2024
1 parent 5e44ee2 commit d1a9bd1
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GPUTest } from '../../../gpu_test.js';
import { checkElementsPassPredicate } from '../../../util/check_contents.js';
import { align } from '../../../util/math.js';
import { PRNG } from '../../../util/prng.js';

/* All buffer sizes are counted in units of 4-byte words. */

Expand Down Expand Up @@ -191,6 +192,7 @@ export class MemoryModelTester {
protected testBindGroup: GPUBindGroup;
protected resultPipeline: GPUComputePipeline;
protected resultBindGroup: GPUBindGroup;
protected prng: PRNG;

/** Sets up a memory model test by initializing buffers and pipeline layouts. */
constructor(
Expand All @@ -200,6 +202,7 @@ export class MemoryModelTester {
resultShader: string,
accessValueType: AccessValueType = 'u32'
) {
this.prng = new PRNG(1);
this.test = t;
this.params = params;

Expand Down Expand Up @@ -519,12 +522,12 @@ export class MemoryModelTester {
);
}

/** Returns a random integer between 0 and the max. */
/** Returns a random integer in the range [0, max). */
protected getRandomInt(max: number): number {
return Math.floor(Math.random() * max);
return this.prng.randomU32() % max;
}

/** Returns a random number in between the min and max values. */
/** Returns a random number in the range [min, max). */
protected getRandomInRange(min: number, max: number): number {
if (min === max) {
return min;
Expand Down

0 comments on commit d1a9bd1

Please sign in to comment.