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

Fix random distribution in bitArray.PickRandom #2534

Merged
merged 2 commits into from Oct 5, 2018
Merged

Conversation

ValarDragon
Copy link
Contributor

Previously it was very biased. 63 "_" followed by a single "x" had
much greater odds of being chosen. Additionally, the last element was
skewed. This fixes that by first preproccessing the set of all true
indices, and then randomly selecting a single element from there.

This commit also makes the code here significantly simpler, and
improves test cases.

  • Updated all relevant documentation in docs - n/a
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

@codecov-io
Copy link

codecov-io commented Oct 3, 2018

Codecov Report

Merging #2534 into develop will increase coverage by 0.02%.
The diff coverage is 100%.

@@             Coverage Diff             @@
##           develop    #2534      +/-   ##
===========================================
+ Coverage    61.26%   61.28%   +0.02%     
===========================================
  Files          202      202              
  Lines        16681    16723      +42     
===========================================
+ Hits         10219    10249      +30     
- Misses        5596     5608      +12     
  Partials       866      866
Impacted Files Coverage Δ
libs/common/bit_array.go 80.08% <100%> (+3.46%) ⬆️
p2p/pex/pex_reactor.go 74% <0%> (-1%) ⬇️
consensus/reactor.go 72.09% <0%> (-0.52%) ⬇️
p2p/pex/addrbook.go 69.58% <0%> (-0.49%) ⬇️
consensus/state.go 77.54% <0%> (+0.23%) ⬆️
libs/clist/clist.go 66.66% <0%> (+4.04%) ⬆️
libs/db/remotedb/remotedb.go 41.52% <0%> (+4.68%) ⬆️

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

🍰 🌮 🍉

Nice

libs/common/bit_array.go Show resolved Hide resolved
ValarDragon and others added 2 commits October 4, 2018 12:39
Previously it was very biased. 63 "_" followed by a single "x" had
much greater odds of being chosen. Additionally, the last element was
skewed. This fixes that by first preproccessing the set of all true
indices, and then randomly selecting a single element from there.

This commit also makes the code here significantly simpler, and
improves test cases.
@melekes melekes merged commit c648c93 into develop Oct 5, 2018
@melekes melekes deleted the dev/pick_random branch October 5, 2018 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants