[tests] Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution} #10547

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:remove-boost-random-dependency changing 1 files +4 −6
  1. practicalswift commented at 12:18 PM on June 7, 2017: contributor

    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.

  2. fanquake added the label Refactoring on Jun 7, 2017
  3. fanquake added the label Tests on Jun 7, 2017
  4. fanquake added this to the "In progress" column in a project

  5. laanwj commented at 12:27 PM on June 7, 2017: member

    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...)

  6. practicalswift renamed this:
    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
    on Jun 7, 2017
  7. practicalswift force-pushed on Jun 7, 2017
  8. practicalswift renamed this:
    [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}
    on Jun 7, 2017
  9. practicalswift commented at 2:41 PM on June 7, 2017: contributor

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

  10. laanwj commented at 2:46 PM on June 7, 2017: member

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

  11. in src/test/scheduler_tests.cpp:60 in 27932fb7f4 outdated
      59 | -    boost::random::uniform_int_distribution<> randomMsec(-11, 1000);
      60 | -    boost::random::uniform_int_distribution<> randomDelta(-1000, 1000);
      61 | +    FastRandomContext rng(42);
      62 | +    auto zeroToNine = [](FastRandomContext& rc) { return rc.randrange(10); }; // [0, 9]
      63 | +    auto randomMsec = [](FastRandomContext& rc) { return -11 + rc.randrange(1012); }; // [-11, 1000]
      64 | +    auto randomDelta = [](FastRandomContext& rc) { return -1000 + rc.randrange(2001); }; // [-1000, 1000]
    


    MarcoFalke commented at 4:04 PM on June 7, 2017:

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


    laanwj commented at 4:22 PM on June 7, 2017:

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


    practicalswift commented at 4:54 PM on June 7, 2017:

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

  12. MarcoFalke changes_requested
  13. practicalswift force-pushed on Jun 7, 2017
  14. [tests] Use FastRandomContext instead of boost::random::{mt19937,uniform_int_distribution} 227ae9b34d
  15. practicalswift force-pushed on Jun 7, 2017
  16. gmaxwell approved
  17. gmaxwell commented at 12:51 AM on June 8, 2017: contributor

    utACK

  18. jonasschnelli commented at 6:27 AM on June 8, 2017: contributor

    utACK 227ae9b34dce632e42ca9f22139e6efad0485df1. Great use of lambdas.

  19. laanwj merged this on Jun 8, 2017
  20. laanwj closed this on Jun 8, 2017

  21. laanwj referenced this in commit 71ab6e5538 on Jun 8, 2017
  22. fanquake moved this from the "In progress" to the "Done" column in a project

  23. PastaPastaPasta referenced this in commit 285ad02561 on Jul 5, 2019
  24. PastaPastaPasta referenced this in commit 1ddaf38aef on Jul 5, 2019
  25. PastaPastaPasta referenced this in commit 16dbe6edaa on Jul 6, 2019
  26. PastaPastaPasta referenced this in commit b6dc579be8 on Jul 8, 2019
  27. barrystyle referenced this in commit 486ab25565 on Jan 22, 2020
  28. practicalswift deleted the branch on Apr 10, 2021
  29. random-zebra referenced this in commit 0e757ad2c9 on Feb 9, 2022
  30. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me