google-deepmind / google-deepmind/torch-randomkit

Override math.random[seed]()

Open
#38 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Lua
Stars
35
Forks
25
PR merge metrics
No merged PRs in 30d

Description

Discussing with @andreirusu this morning: how about having randomkit offering the possibility to override `math.random()` with either of:
- for debugging purposes:

``` lua
math.random = function(...)
error('Thou shall not use lua RNG, use torch instead!')
end

math.randomseed = function(...)
error('Thou shall not use lua RNG, use torch instead!')
end
```

or
- for single-RNG purposes

``` lua
math.random = function(...)
return -- call to torch.random() with proper parameters

math.randomseed = function(arg)
torch.manualSeed(arg)
end
```

As an added bonus, that would allow us to get the full _current state_ of the RNG, which torch offers via `getRNGState()`, as opposed to getting only the initial seed -- the only thing that lua offers.

We could make all of this either the default behaviour, or a function that the user can calls, e.g. `randomkit.unifyRNGs()`, or even something settable at loading time with a call like
`require 'randomkit'({unifyRNGs = true})`.

What do you think, @akfidjeland ? I think @tomschaul might be interested too.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.