Skip to content

Commit

Permalink
Adding getCurrentSeed()
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekctek committed Oct 29, 2023
1 parent ed4df18 commit dc9e892
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/PseudoRandomX.mo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Nat32 "mo:base/Nat32";
module Module {

public type PseudoRandomGenerator = {
getCurrentSeed : () -> Nat32;
nextInt : (min : Int, max : Int) -> Int;
nextNat : (min : Nat, max : Nat) -> Nat;
nextCoin : () -> Bool;
Expand All @@ -22,15 +23,19 @@ module Module {
};

public class LinearCongruentialGenerator(seed : Nat32) : PseudoRandomGenerator {
var currentValue = seed;
var currentSeed = seed;
let a : Nat32 = 1664525;
let c : Nat32 = 1013904223;

private func nextSeed() : Nat32 {
currentValue := currentValue
currentSeed := currentSeed
|> Nat32.mulWrap(a, _)
|> Nat32.addWrap(_, c); // Overflow is ok
return currentValue;
return currentSeed;
};

public func getCurrentSeed() : Nat32 {
currentSeed;
};

public func nextInt(min : Int, max : Int) : Int {
Expand Down

0 comments on commit dc9e892

Please sign in to comment.