Skip to content

Commit

Permalink
Fixing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekctek committed Feb 18, 2024
1 parent 6380731 commit 0a02c4b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PseudoRandomX.mo
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ module Module {
blob.vals(),
func(byte : Nat8, i : Nat) {
// Determine the position of the byte within its 4-byte chunk
let bytePosition : Nat32 = Nat32.fromNat(i) % 4;
let bytePosition : Nat32 = Nat32.fromNat(i % 4);
let nat32Byte = Nat32.fromNat(Nat8.toNat(byte));
// Shift the byte to its correct position and combine it with the current seed using XOR
let shiftedByte = Nat32.bitshiftLeft(nat32Byte, (3 - bytePosition) * 8);
seed := Nat32.bitxor(seed, shiftedByte);

// Every 4 bytes, optionally mix the seed to ensure even distribution of entropy
if ((i + 1) % 4 == 0) {
seed := Nat32.bitxor(Nat32.mul(seed, 2654435761), Nat32.bitrotLeft(seed, 13));
seed := Nat32.bitxor(Nat32.mulWrap(seed, 2654435761), Nat32.bitrotLeft(seed, 13));
};
},
);
Expand Down

0 comments on commit 0a02c4b

Please sign in to comment.