File tree Expand file tree Collapse file tree
src/Data/Nat/PseudoRandom Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ Non-backwards compatible changes
2424Minor improvements
2525------------------
2626
27+ * The function ` Data.Nat.LCG.step ` is now a manifest field of the record type
28+ ` Generator ` , as per the discussion on #2936 and upstream issues/PRs. This is
29+ consistent with a minimal API for such LCGs, and should be backwards compatible.
30+
2731* The types of ` Data.Vec.Base.{truncate|padRight} ` have been weakened so
2832 that the argument of type ` m ≤ n ` is marked as irrelevant. This should be
2933 backwards compatible, but does change the intensional behaviour of these
Original file line number Diff line number Diff line change 99
1010module Data.Nat.PseudoRandom.LCG where
1111
12- open import Data.Nat.Base
12+ open import Data.Nat.Base using (ℕ; _+_; _*_; _^_; NonZero)
1313open import Data.Nat.DivMod using (_%_)
14- open import Data.List.Base using (List; []; _∷_ )
14+ open import Data.List.Base using (List; iterate )
1515
1616------------------------------------------------------------------------
1717-- Type and generator
@@ -22,14 +22,13 @@ record Generator : Set where
2222 modulus : ℕ
2323 .{{modulus≢0}} : NonZero modulus
2424
25- step : Generator → ℕ → ℕ
26- step gen@record{} x =
27- let open Generator gen in
28- ((multiplier * x + increment) % modulus )
25+ step : ℕ → ℕ
26+ step x = (multiplier * x + increment) % modulus
27+
28+ open Generator public using (step )
2929
3030list : ℕ → Generator → ℕ → List ℕ
31- list zero gen x = []
32- list (suc k) gen x = x ∷ list k gen (step gen x)
31+ list k gen x = iterate (step gen) x k
3332
3433------------------------------------------------------------------------
3534-- Examples of parameters
Original file line number Diff line number Diff line change 88
99{-# OPTIONS --cubical-compatible --sized-types #-}
1010
11- open import Codata.Sized.Stream using (Stream; unfold )
11+ open import Codata.Sized.Stream using (Stream; iterate )
1212open import Data.Nat.PseudoRandom.LCG using (Generator; step)
1313open import Data.Nat.Base using (ℕ)
14- open import Data.Product.Base using (<_,_>)
15- open import Function.Base using (id)
14+ open import Function.Base using (_∘_)
1615
1716module Data.Nat.PseudoRandom.LCG.Unsafe where
1817
1918------------------------------------------------------------------------
2019-- An infinite stream of random numbers
2120
2221stream : Generator → ℕ → Stream ℕ _
23- stream gen = unfold < step gen , id >
22+ stream = iterate ∘ step
You can’t perform that action at this time.
0 commit comments