Skip to content

Commit

Permalink
changelog + fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Mar 23, 2021
1 parent 97f2092 commit ecf4454
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
16 changes: 11 additions & 5 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
- Added `randState` template that exposes the default random number generator.
Useful for library authors.

- Added `random.initRand()` overload with no argument which uses the current time as a seed.

- `random.initRand(seed)` now allows `seed == 0`

- `random.initRand(seed)` now produces non-skewed values for the 1st call to rand() after
initialization with a small (< 30000) seed. Use `-d:nimLegacyRandomInitRand` to restore
previous behavior for a transition time, see PR #17467.

- Added `std/sysrand` module to get random numbers from a secure source
provided by the operating system.

- Added `std/enumutils` module. Added `genEnumCaseStmt` macro that generates case statement to parse string to enum.
Added `items` for enums with holes.
Added `symbolName` to return the enum symbol name ignoring the human readable name.
Expand Down Expand Up @@ -148,9 +159,6 @@

- Deprecated `any`. See https://github.com/nim-lang/RFCs/issues/281

- Added `std/sysrand` module to get random numbers from a secure source
provided by the operating system.

- Added optional `options` argument to `copyFile`, `copyFileToDir`, and
`copyFileWithPermissions`. By default, on non-Windows OSes, symlinks are
followed (copy files symlinks point to); on Windows, `options` argument is
Expand All @@ -168,8 +176,6 @@
- Added `os.isAdmin` to tell whether the caller's process is a member of the
Administrators local group (on Windows) or a root (on POSIX).

- Added `random.initRand()` overload with no argument which uses the current time as a seed.

- Added experimental `linenoise.readLineStatus` to get line and status (e.g. ctrl-D or ctrl-C).

- Added `compilesettings.SingleValueSetting.libPath`.
Expand Down
5 changes: 4 additions & 1 deletion lib/pure/random.nim
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,10 @@ proc initRand*(seed: int64): Rand =
let seed = if seed != 0: seed else: 1 # because 0 is a fixed point
result.a0 = Ui(seed shr 16)
result.a1 = Ui(seed and 0xffff)
skipRandomNumbers(result)
when not defined(nimLegacyRandomInitRand):
# calling `discard next(result)` (even a few times) would still produce
# skewed numbers for the 1st call to `rand()`.
skipRandomNumbers(result)
discard next(result)

proc randomize*(seed: int64) {.benign.} =
Expand Down
2 changes: 1 addition & 1 deletion tests/stdlib/trandom.nim
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ block:
var r2 = initRand(124)
doAssert r1.rand(1.0) != r2.rand(1.0)

block: # bug https://github.com/timotheecour/Nim/issues/435
block: # bug #17467
let n = 1000
for i in -n .. n:
var r = initRand(i)
Expand Down

0 comments on commit ecf4454

Please sign in to comment.