@@ -160,6 +160,7 @@ import Data.Aeson.Types (Pair)
160160import qualified Data.Binary.Put as B
161161import qualified Data.ByteString as BS
162162import qualified Data.ByteString.Lazy as BSL
163+ import Data.Coerce (coerce )
163164import Data.Default (Default (def ))
164165import qualified Data.Fixed as FP (Fixed , HasResolution , resolution )
165166import Data.Functor.Identity (Identity )
@@ -186,6 +187,7 @@ import GHC.Stack (HasCallStack)
186187import NoThunks.Class (NoThunks (.. ))
187188import Numeric.Natural (Natural )
188189import Quiet (Quiet (Quiet ))
190+ import System.Random.Stateful (Random , Uniform (.. ), UniformRange (.. ))
189191
190192maxDecimalsWord64 :: Int
191193maxDecimalsWord64 = 19
@@ -832,6 +834,14 @@ newtype TxIx = TxIx {unTxIx :: Word16}
832834 deriving newtype
833835 (NFData , Enum , Bounded , NoThunks , FromCBOR , ToCBOR , EncCBOR , DecCBOR , ToJSON , MemPack )
834836
837+ instance Random TxIx
838+
839+ instance Uniform TxIx where
840+ uniformM g = TxIx <$> uniformM g
841+
842+ instance UniformRange TxIx where
843+ uniformRM r g = TxIx <$> uniformRM (coerce r) g
844+
835845-- | Construct a `TxIx` from a 16 bit unsigned integer
836846mkTxIx :: Word16 -> TxIx
837847mkTxIx = TxIx . fromIntegral
@@ -857,6 +867,14 @@ newtype CertIx = CertIx {unCertIx :: Word16}
857867 deriving stock (Eq , Ord , Show )
858868 deriving newtype (NFData , Enum , Bounded , NoThunks , EncCBOR , DecCBOR , ToCBOR , FromCBOR , ToJSON )
859869
870+ instance Random CertIx
871+
872+ instance Uniform CertIx where
873+ uniformM g = CertIx <$> uniformM g
874+
875+ instance UniformRange CertIx where
876+ uniformRM r g = CertIx <$> uniformRM (coerce r) g
877+
860878-- | Construct a `CertIx` from a 16 bit unsigned integer
861879mkCertIx :: Word16 -> CertIx
862880mkCertIx = CertIx . fromIntegral
0 commit comments