From 53d9902347dad9e22171f643916e830c1b20872c Mon Sep 17 00:00:00 2001 From: Antonis Geralis <43617260+planetis-m@users.noreply.github.com> Date: Thu, 29 Oct 2020 12:14:22 +0200 Subject: [PATCH] Make default state public (#15763) * Make default state public * Address review comments Co-authored-by: b3liever --- changelog.md | 2 +- lib/pure/random.nim | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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))