fix exception signature and docs

This commit is contained in:
gmega 2025-02-24 11:26:30 -03:00
parent fcdeb1c31e
commit 355de6d8e6
No known key found for this signature in database
GPG Key ID: 6290D34EAD824B18

View File

@ -35,7 +35,7 @@ proc rand*(rng: Rng, max: Natural): int =
if x < randMax - (randMax mod (uint64(max) + 1'u64)): # against modulo bias
return int(x mod (uint64(max) + 1'u64))
proc sampleNoReplacement[T](a: seq[T], n: int): seq[T] =
proc sampleNoReplacement[T](a: seq[T], n: int): seq[T] {.raises: [RngSampleError].} =
if n > a.len:
raise newException(
RngSampleError,
@ -60,11 +60,12 @@ proc sampleWithReplacement[T](a: seq[T], n: int): seq[T] =
proc sample*[T](rng: Rng, a: openArray[T]): T =
result = a[rng.rand(a.high)]
proc sample*[T](rng: Rng, a: seq[T], n: int, replace: bool = false): seq[T] =
## Sample `n` elements from a set `a` with or without replacement. In case of
## sampling with replacement, `n` must not be greater than the size of `a`.
proc sample*[T](
rng: Rng, a: seq[T], n: int, replace: bool = false
): seq[T] {.raises: [RngSampleError].} =
## Sample `n` elements from a set `a` with or without replacement.
## In case of sampling without replacement, `n` must not be greater than the
## size of `a` minus 1.
## size of `a`.
if replace:
sampleWithReplacement(a, n)
else: