Skip to content

Conversation

practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Jun 7, 2017

Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution}.

Was:

Use std::random::mt19937/uniform_int_distribution (C++11) instead of boost::random equivalents.

@laanwj
Copy link
Member

laanwj commented Jun 7, 2017

Why not use our own FastRandomContext? This only uses linear random, so I'd say there's no need to add a dependency on std::random::mt19937.

(though getting rid of the boost one is good...)

@practicalswift practicalswift changed the title Use std::random::mt19937/uniform_int_distribution (C++11) instead of boost::random equivalents [tests] Use std::random::mt19937/uniform_int_distribution (C++11) instead of boost::random equivalents Jun 7, 2017
@practicalswift practicalswift force-pushed the remove-boost-random-dependency branch from 305618b to 27932fb Compare June 7, 2017 14:38
@practicalswift practicalswift changed the title [tests] Use std::random::mt19937/uniform_int_distribution (C++11) instead of boost::random equivalents [tests] Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution} Jun 7, 2017
@practicalswift
Copy link
Contributor Author

@laanwj Good idea! Now using FastRandomContext. Looks OK now?

@laanwj
Copy link
Member

laanwj commented Jun 7, 2017

Yes, that's a cool minimal-impact solution using the lambda expressions.

FastRandomContext rng(42);
auto zeroToNine = [](FastRandomContext& rc) { return rc.randrange(10); }; // [0, 9]
auto randomMsec = [](FastRandomContext& rc) { return -11 + rc.randrange(1012); }; // [-11, 1000]
auto randomDelta = [](FastRandomContext& rc) { return -1000 + rc.randrange(2001); }; // [-1000, 1000]
Copy link
Member

Choose a reason for hiding this comment

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

This lambda returns an unsigned expression and such can never be negative.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, hadn't realized randrange returns an unsigned value. This is a risk with auto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarcoFalke Oh, good catch! Now explicitly setting the return type. Thanks a lot for noticing!

@practicalswift practicalswift force-pushed the remove-boost-random-dependency branch from 27932fb to 32c317d Compare June 7, 2017 16:38
@practicalswift practicalswift force-pushed the remove-boost-random-dependency branch from 32c317d to 227ae9b Compare June 7, 2017 18:38
Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

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

utACK

@jonasschnelli
Copy link
Contributor

utACK 227ae9b.
Great use of lambdas.

@laanwj laanwj merged commit 227ae9b into bitcoin:master Jun 8, 2017
laanwj added a commit that referenced this pull request Jun 8, 2017
…:{mt19937,uniform_int_distribution}

227ae9b [tests] Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution} (practicalswift)

Tree-SHA512: 1bde6c8b9498051fa2eae4913eb1f5411adea8dea1511c0df859aea57a2a7db6f5839945ddf2eccdddfa322bceacad35a5d875742db7d15e40dbea83185307bb
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 5, 2019
…random::{mt19937,uniform_int_distribution}

227ae9b [tests] Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution} (practicalswift)

Tree-SHA512: 1bde6c8b9498051fa2eae4913eb1f5411adea8dea1511c0df859aea57a2a7db6f5839945ddf2eccdddfa322bceacad35a5d875742db7d15e40dbea83185307bb
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 5, 2019
…random::{mt19937,uniform_int_distribution}

227ae9b [tests] Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution} (practicalswift)

Tree-SHA512: 1bde6c8b9498051fa2eae4913eb1f5411adea8dea1511c0df859aea57a2a7db6f5839945ddf2eccdddfa322bceacad35a5d875742db7d15e40dbea83185307bb
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 6, 2019
…random::{mt19937,uniform_int_distribution}

227ae9b [tests] Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution} (practicalswift)

Tree-SHA512: 1bde6c8b9498051fa2eae4913eb1f5411adea8dea1511c0df859aea57a2a7db6f5839945ddf2eccdddfa322bceacad35a5d875742db7d15e40dbea83185307bb
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 8, 2019
…random::{mt19937,uniform_int_distribution}

227ae9b [tests] Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution} (practicalswift)

Tree-SHA512: 1bde6c8b9498051fa2eae4913eb1f5411adea8dea1511c0df859aea57a2a7db6f5839945ddf2eccdddfa322bceacad35a5d875742db7d15e40dbea83185307bb
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
…random::{mt19937,uniform_int_distribution}

227ae9b [tests] Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution} (practicalswift)

Tree-SHA512: 1bde6c8b9498051fa2eae4913eb1f5411adea8dea1511c0df859aea57a2a7db6f5839945ddf2eccdddfa322bceacad35a5d875742db7d15e40dbea83185307bb
@practicalswift practicalswift deleted the remove-boost-random-dependency branch April 10, 2021 19:31
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Feb 9, 2022
ad5717d Lint: Add lint-includes.sh (Fuzzbawls)
faba3f6 [tests] Use FastRandomContext in scheduler_tests.cpp (practicalswift)
2034bf6 Remove unused boost includes in reverselock_tests.cpp (Fuzzbawls)
3256d16 bench: Use non-throwing ParseDouble() (Fuzzbawls)
3c984d1 Remove duplicate includes (Fuzzbawls)
b54e396 Declare TorReply parsing functions in torcontrol_tests (Fuzzbawls)

Pull request description:

  This brings in the `lint-includes.sh` shell script from upstream (first introduced in bitcoin#11878) to automatically check for duplicate includes and expanded in bitcoin#13301 and bitcoin#13385 to check for the inclusion of `.cpp` files and the introduction of new boost includes, respectively.

  The check for enforcing bracket include syntax (bitcoin#13230) is also included, but currently disabled, as we have yet to systematically switch to that syntax preference.

  Three other upstream PRs are backported here as they are directly related to the removal of some boost dependencies and are very straight forward:
  - bitcoin#10547
  - bitcoin#13291
  - bitcoin#13383

  **NOTE: #2711 removes the dependency on `boost/tuple/tuple.hpp`, so it makes sense to merge that first. submitting this now so the general concept/functionality can be reviewed prior to that PR being merged**

ACKs for top commit:
  furszy:
    good ACK ad5717d
  random-zebra:
    utACK ad5717d and merging...

Tree-SHA512: d9d32d6d5122dac52c9601cda75612d87c4e027c6f196a2382206b227fcfd2bb61d4f72df7cbf5e572d94150ad8ca6db6301bd99b0da647b9627fe342b66873f
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants