Skip to content

[EASY] Use a static random_device in StorageSharing#9080

Closed
apaszke wants to merge 1 commit intomasterfrom
random_device
Closed

[EASY] Use a static random_device in StorageSharing#9080
apaszke wants to merge 1 commit intomasterfrom
random_device

Conversation

@apaszke
Copy link
Contributor

@apaszke apaszke commented Jul 1, 2018

I've been cleaning up my email notifications, and noticed that this PR used a stack-allocated random_device. This is generally a bad idea due to this sentence from the C++ reference (emphasis mine):

std::random_device may be implemented in terms of an implementation-defined pseudo-random number engine if a non-deterministic source (e.g. a hardware device) is not available to the implementation. In this case each std::random_device object may generate the same number sequence.

If this is how this object is implemented, then this rd() call will give the same result at every call.

cc @yf225

@apaszke apaszke requested a review from yf225 July 1, 2018 17:35
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soumith is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
Summary:
I've been cleaning up my email notifications, and noticed that this PR used a stack-allocated `random_device`. This is generally a bad idea due to this sentence from the C++ reference (emphasis mine):

> `std::random_device` may be implemented in terms of an implementation-defined pseudo-random number engine if a non-deterministic source (e.g. a hardware device) is not available to the implementation. **In this case each `std::random_device` object may generate the same number sequence.**

If this is how this object is implemented, then this `rd()` call will give the same result at every call.

cc yf225
Closes pytorch#9080

Differential Revision: D8748342

Pulled By: soumith

fbshipit-source-id: 22987befee61ff7faacda5ecc10138c2ac5d26ff
@soumith soumith deleted the random_device branch February 21, 2019 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants