Skip to content

Commit

Permalink
Merge pull request #13 from savi-lang/update/latest-savi
Browse files Browse the repository at this point in the history
Update for latest Savi syntax.
  • Loading branch information
jemc authored Jun 21, 2023
2 parents ad9bea8 + 5c54f82 commit 94dc3d6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Random.savi
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@
product = random.u64.wide_multiply(limit)
// Reject and try again if the tail happens to be in the zone of bias.
// The loop will continue generating new numbers until we get a good sample.
if (product.tail < limit) (
if product.tail < limit (
threshold = limit.negate % limit
while (product.tail < threshold) (
while product.tail < threshold (
product = random.u64.wide_multiply(limit)
)
)
Expand All @@ -128,9 +128,9 @@
product = random.u32.wide_multiply(limit)
// Reject and try again if the tail happens to be in the zone of bias.
// The loop will continue generating new numbers until we get a good sample.
if (product.tail < limit) (
if product.tail < limit (
threshold = limit.negate % limit
while (product.tail < threshold) (
while product.tail < threshold (
product = random.u32.wide_multiply(limit)
)
)
Expand All @@ -146,7 +146,7 @@
:: If you need fully unbiased results, use the `unbiased_u32_less_than`
:: method instead, which discards all samples from the biased zone.
:fun ref usize_less_than(limit USize)
if (USize.bit_width == 32) (
if USize.bit_width == 32 (
@u32_less_than(limit.u32).usize
|
@u64_less_than(limit.u64).usize
Expand All @@ -162,7 +162,7 @@
:: To keep maximum performance at the cost of some possibility of bias,
:: use the `uSize_less_than` method instead, which never discards results.
:fun ref unbiased_usize_less_than(limit USize) USize
if (USize.bit_width == 32) (
if USize.bit_width == 32 (
@unbiased_u32_less_than(limit.u32).usize
|
@unbiased_u64_less_than(limit.u64).usize
Expand All @@ -186,7 +186,7 @@
:fun ref random_bytes(size USize) Bytes
bytes = Bytes.new_iso(size)

while (size > 0) (
while size > 0 (
case size > (
| 8 | bytes.push_native_u64(@u64), size -= 8
| 4 | bytes.push_native_u32(@u32), size -= 4
Expand Down

0 comments on commit 94dc3d6

Please sign in to comment.