@@ -18,7 +18,7 @@ object Random {
1818
1919 def apply [F [_]](using F : Random [F ]): Random [F ] = F
2020
21- extension [F [_]](self : Random [F ]){
21+ extension [F [_]](self : Random [F ]) {
2222 def mapK [G [_]](f : F ~> G ): Random [G ] = new Random [G ] {
2323 def int = f(self.int)
2424 def long = f(self.long)
@@ -27,7 +27,6 @@ object Random {
2727 }
2828 }
2929
30-
3130 type SeedT [A ] = cats.data.StateT [Id , Seed , A ]
3231
3332 object SeedT {
@@ -41,7 +40,7 @@ object Random {
4140 def next (bits : Int ): SeedT [Int ] = {
4241 SeedT { seed =>
4342 val r = (seed >>> (48 - bits)).toInt
44- val s1 = (seed * 0x5DEECE66DL + 0xBL ) & ((1L << 48 ) - 1 )
43+ val s1 = (seed * 0x5deece66dL + 0xbL ) & ((1L << 48 ) - 1 )
4544 (s1, r)
4645 }
4746 }
@@ -53,36 +52,32 @@ object Random {
5352 def long = {
5453 for
5554 a0 <- next(32 )
56- a1 = a0.toLong << 32
55+ a1 = a0.toLong << 32
5756 a2 <- next(32 )
58- yield
59- a1 + a2
57+ yield a1 + a2
6058 }
6159
6260 def float = {
63- for
64- a <- next(24 )
65- yield
66- a / floatUnit
61+ for a <- next(24 )
62+ yield a / floatUnit
6763 }
6864
6965 def double = {
7066 for
7167 a0 <- next(26 )
72- a1 = a0.toLong << 27
68+ a1 = a0.toLong << 27
7369 a2 <- next(27 )
74- yield
75- (a1 + a2) * doubleUnit
70+ yield (a1 + a2) * doubleUnit
7671 }
7772 }
7873 }
7974
80-
81- def apply [ A ]( f : Seed => ( Seed , A )) : SeedT [ A ] = cats.data.StateT [Id , Seed , A ] { seed => f(seed) }
75+ def apply [ A ]( f : Seed => ( Seed , A )) : SeedT [ A ] =
76+ cats.data.StateT [Id , Seed , A ] { seed => f(seed) }
8277 }
8378
84-
85- final case class State ( seed : Seed , random : Random [ SeedT ] = SeedT . Random ) extends Random [State .Type ] {
79+ final case class State ( seed : Seed , random : Random [ SeedT ] = SeedT . Random )
80+ extends Random [State .Type ] {
8681
8782 private def apply [A ](stateT : SeedT [A ]) = {
8883 val (seed1, a) = stateT.run(seed)
@@ -99,11 +94,13 @@ object Random {
9994
10095 type Type [A ] = (State , A )
10196
102- def fromClock [F [_]: Clock : FlatMap ](random : Random [SeedT ] = SeedT .Random ): F [State ] = {
103- for
104- nanos <- Clock [F ].nanos
97+ def fromClock [F [_]: Clock : FlatMap ](
98+ random : Random [SeedT ] = SeedT .Random
99+ ): F [State ] = {
100+ for nanos <- Clock [F ].nanos
105101 yield
106- val seed = (nanos ^ 3447679086515839964L ^ 0x5DEECE66DL) & ((1L << 48 ) - 1 )
102+ val seed =
103+ (nanos ^ 3447679086515839964L ^ 0x5deece66dL) & ((1L << 48 ) - 1 )
107104 apply(seed, random)
108105 }
109106 }
0 commit comments