Skip to content

Commit

Permalink
Fix getRandomInt boundaries (#1348)
Browse files Browse the repository at this point in the history
n-bit signed integers on two's complement systems range from
-(2^(n-1)) to 2^(n-1)-1
  • Loading branch information
elopez authored Feb 7, 2025
1 parent 9ed5cb6 commit 3a3e8b6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Echidna/ABI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ getRandomUint n =

-- | Generate a random signed integer with the following distribution:
-- * 10% uniformly from the range -1023 to 1023.
-- * 90% uniformly from the range -1 * 2 ^ n to 2 ^ (n - 1).
-- * 90% uniformly from the range -1 * 2 ^ (n - 1) to 2 ^ (n - 1) - 1.
getRandomInt :: MonadRandom m => Int -> m Integer
getRandomInt n =
getRandomR =<< Random.weighted
[ ((-1023, 1023), 1)
, ((-1 * 2 ^ n, 2 ^ (n - 1)), 9)
, ((-1 * 2 ^ (n - 1), 2 ^ (n - 1) - 1), 9)
]

-- | Synthesize a random 'AbiValue' given its 'AbiType'. Doesn't use a dictionary.
Expand Down

0 comments on commit 3a3e8b6

Please sign in to comment.