diff --git a/changelog.md b/changelog.md index 7f1034376..7c7640207 100644 --- a/changelog.md +++ b/changelog.md @@ -7,7 +7,7 @@ - `prelude` now works with the JavaScript target. - Added `ioutils` module containing `duplicate` and `duplicateTo` to duplicate `FileHandle` using C function `dup` and `dup2`. - +- Added `randState` template that exposes the default random number generator. Useful for library authors. ## Language changes diff --git a/lib/pure/random.nim b/lib/pure/random.nim index 7c5d51ceb..3d9948d08 100644 --- a/lib/pure/random.nim +++ b/lib/pure/random.nim @@ -119,6 +119,12 @@ else: a0: 0x69B4C98CB8530805u64, a1: 0xFED1DD3004688D67CAu64) # global for backwards compatibility +since (1, 5): + template randState*(): untyped = + ## Makes the default Rand state accessible from other modules. + ## Useful for module authors. + state + proc rotl(x, k: Ui): Ui = result = (x shl k) or (x shr (Ui(64) - k))