Opened 11 years ago
Last modified 7 years ago
#10634 needs_work enhancement
Weighted Choice
Reported by: | eviatarbach | Owned by: | jason |
---|---|---|---|
Priority: | minor | Milestone: | sage-6.4 |
Component: | misc | Keywords: | |
Cc: | Merged in: | ||
Authors: | Eviatar Bach | Reviewers: | |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
This adds weighted choice to the choice function in prandom.py.
Attachments (1)
Change History (8)
Changed 11 years ago by
comment:1 Changed 11 years ago by
- Status changed from new to needs_review
comment:2 Changed 11 years ago by
comment:3 Changed 11 years ago by
- Status changed from needs_review to needs_work
Until the previous comments are addressed/answered... :-)
Oh, and it would be nice to keep the lines to less than 80 characters !
Nathann
comment:4 Changed 8 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:5 Changed 8 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:6 Changed 8 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:7 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
Note: See
TracTickets for help on using
tickets.
A few points:
(1) There are a few typos in the doc ("choose choose", and "if given a list" reads better than "if inputted a list").
(2) The use of factor=1/max(seq.values()) means that the code can run forever if the maximum weight is a Python integer > 1, because then factor becomes 0.
(3) I don't know if it matters, but the while True approach can be quite inefficient for large arrays, because the odds of succeeding on any given try can be pretty low: