Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate std/mersenne #18395

Merged
merged 20 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/pure/mersenne.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
#
# Nim's Runtime Library
# (c) Copyright 2015 Nim Contributors
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#

## The [Mersenne Twister](https://en.wikipedia.org/wiki/Mersenne_Twister)
## random number generator.
##
## **Note:** The procs in this module work at compile-time.
## .. note:: The procs in this module work at compile-time.
{.deprecated:"import std/random instead.".}
Araq marked this conversation as resolved.
Show resolved Hide resolved

runnableExamples:
var rand = newMersenneTwister(uint32.high) ## must be "var"
doAssert rand.getNum() != rand.getNum() ## pseudorandom number

## See also
## ========
## * `random module<random.html>`_ for Nim's standard random number generator

type
MersenneTwister* = object
## The Mersenne Twister.
Expand All @@ -35,6 +30,7 @@ proc newMersenneTwister*(seed: uint32): MersenneTwister =
(result.mt[i-1] shr 30'u32)) + i)

proc generateNumbers(m: var MersenneTwister) =

qaziquza marked this conversation as resolved.
Show resolved Hide resolved
for i in 0..623:
var y = (m.mt[i] and 0x80000000'u32) +
(m.mt[(i+1) mod 624] and 0x7fffffff'u32)
Expand All @@ -48,7 +44,6 @@ proc getNum*(m: var MersenneTwister): uint32 =
generateNumbers(m)
result = m.mt[m.index]
m.index = (m.index + 1) mod m.mt.len

result = result xor (result shr 11'u32)
result = result xor ((result shl 7'u32) and 0x9d2c5680'u32)
result = result xor ((result shl 15'u32) and 0xefc60000'u32)
Expand Down
1 change: 1 addition & 0 deletions tests/stdlib/tmersenne.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ template main() =
doAssert mt.getNum == 1071751096'u32
doAssert mt.getNum == 3805347140'u32


static: main()
main()