MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / generateBytes

Method generateBytes

src/utils/random/seedrandom.ts:45–75  ·  view source on GitHub ↗
(array: Uint8Array)

Source from the content-addressed store, hash-verified

43 }
44
45 public generateBytes(array: Uint8Array): Uint8Array {
46 if (array.length < 1) return array;
47 array.fill(0);
48 let dst = array;
49 if (dst.length <= this.filledBuffer.length) {
50 dst.set(this.filledBuffer.subarray(0, dst.length));
51 this.filledBuffer = this.filledBuffer.subarray(dst.length);
52 return array;
53 } else {
54 while (dst.length > 0) {
55 if (this.filledBuffer.length === 0) {
56 if (dst.length >= seedRandomBlockSize) {
57 const df64 = dst.subarray(0, dst.length - (dst.length % seedRandomBlockSize));
58 this.fillBufferDirect(df64);
59 dst = dst.subarray(df64.length);
60 continue;
61 }
62 this.fillBuffer();
63 }
64 if (dst.length <= this.filledBuffer.length) {
65 dst.set(this.filledBuffer.subarray(0, dst.length));
66 this.filledBuffer = this.filledBuffer.subarray(dst.length);
67 return array;
68 }
69 dst.set(this.filledBuffer);
70 dst = dst.subarray(this.filledBuffer.length);
71 this.fillBuffer();
72 }
73 return array;
74 }
75 }
76}

Callers 1

Calls 3

fillBufferDirectMethod · 0.95
fillBufferMethod · 0.95
setMethod · 0.65

Tested by

no test coverage detected